From addff452bef6ae5d7b12ab19188a74041b58b10c Mon Sep 17 00:00:00 2001 From: N5N3 <2642243996@qq.com> Date: Thu, 24 Oct 2024 07:32:33 +0800 Subject: [PATCH] typeintersect: more fastpath to skip intersect under circular env (#56304) fix #56040 (cherry picked from commit 53ffe5630cff5d974722ec197c6f53b907ffd457) --- src/subtype.c | 9 +++++++-- test/subtype.jl | 9 +++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/subtype.c b/src/subtype.c index 59cba8a895653..70c570ce5b8d7 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -2408,8 +2408,10 @@ static jl_value_t *intersect_aside(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, return y; if (y == (jl_value_t*)jl_any_type && !jl_is_typevar(x)) return x; - // band-aid for #46736 - if (obviously_egal(x, y)) + // band-aid for #46736 #56040 + if (obviously_in_union(x, y)) + return y; + if (obviously_in_union(y, x)) return x; jl_varbinding_t *vars = NULL; @@ -2439,6 +2441,9 @@ static jl_value_t *intersect_aside(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, static jl_value_t *intersect_union(jl_value_t *x, jl_uniontype_t *u, jl_stenv_t *e, int8_t R, int param) { + // band-aid for #56040 + if (!jl_is_uniontype(x) && obviously_in_union((jl_value_t *)u, x)) + return x; int no_free = !jl_has_free_typevars(x) && !jl_has_free_typevars((jl_value_t*)u); if (param == 2 || no_free) { jl_value_t *a=NULL, *b=NULL; diff --git a/test/subtype.jl b/test/subtype.jl index 7be869107b432..dfa1487eaa55d 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -2721,3 +2721,12 @@ let T1 = NTuple{12, Union{Val{1}, Val{2}, Val{3}, Val{4}, Val{5}, Val{6}}} @test !(T1 <: T2) @test Tuple{Union{Val{1},Val{2}}} <: Tuple{S} where {T, S<:Val{T}} end + +#issue 56040 +let S = Dict{V,V} where {V}, + T = Dict{Ref{Union{Set{A2}, Set{A3}, A3}}, Ref{Union{Set{A3}, Set{A2}, Set{A1}, Set{A4}, A4}}} where {A1, A2<:Set{A1}, A3<:Union{Set{A1}, Set{A2}}, A4<:Union{Set{A2}, Set{A1}, Set{A3}}}, + A = Dict{Ref{Set{Union{}}}, Ref{Set{Union{}}}} + @testintersect(S, T, !Union{}) + @test A <: typeintersect(S, T) + @test A <: typeintersect(T, S) +end