Skip to content

Commit

Permalink
typeintersect: more fastpath to skip intersect under circular env (#5…
Browse files Browse the repository at this point in the history
…6304)

fix #56040

(cherry picked from commit 53ffe56)
  • Loading branch information
N5N3 authored and KristofferC committed Oct 24, 2024
1 parent 716cf46 commit addff45
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit addff45

Please sign in to comment.