Skip to content

Commit 028858f

Browse files
N5N3KristofferC
authored andcommitted
typeintersect: more fastpath to skip intersect under circular env (#56304)
fix #56040 (cherry picked from commit 53ffe56)
1 parent b23811e commit 028858f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/subtype.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,8 +2392,10 @@ static jl_value_t *intersect_aside(jl_value_t *x, jl_value_t *y, jl_stenv_t *e,
23922392
return y;
23932393
if (y == (jl_value_t*)jl_any_type && !jl_is_typevar(x))
23942394
return x;
2395-
// band-aid for #46736
2396-
if (obviously_egal(x, y))
2395+
// band-aid for #46736 #56040
2396+
if (obviously_in_union(x, y))
2397+
return y;
2398+
if (obviously_in_union(y, x))
23972399
return x;
23982400

23992401
jl_saved_unionstate_t oldRunions; push_unionstate(&oldRunions, &e->Runions);
@@ -2407,6 +2409,9 @@ static jl_value_t *intersect_aside(jl_value_t *x, jl_value_t *y, jl_stenv_t *e,
24072409

24082410
static jl_value_t *intersect_union(jl_value_t *x, jl_uniontype_t *u, jl_stenv_t *e, int8_t R, int param)
24092411
{
2412+
// band-aid for #56040
2413+
if (!jl_is_uniontype(x) && obviously_in_union((jl_value_t *)u, x))
2414+
return x;
24102415
if (param == 2 || (!jl_has_free_typevars(x) && !jl_has_free_typevars((jl_value_t*)u))) {
24112416
jl_value_t *a=NULL, *b=NULL;
24122417
JL_GC_PUSH2(&a, &b);

test/subtype.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,3 +2641,12 @@ let S = Tuple{Val, Val{T}} where {T}, R = Tuple{Val{Val{T}}, Val{T}} where {T},
26412641
@testintersect(Tuple{Val{A}, A} where {B, A<:Union{Val{B}, NamedTuple{(:a),B}}}, S{NTuple{2,Int}}, R{NTuple{2,Int}})
26422642
@testintersect(Tuple{Val{A}, A} where {B, A<:Union{Val{B}, NamedTuple{B,Tuple{Int,Int}}}}, S{(:a,:a)}, R{(:a,:a)})
26432643
end
2644+
2645+
#issue 56040
2646+
let S = Dict{V,V} where {V},
2647+
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}}},
2648+
A = Dict{Ref{Set{Union{}}}, Ref{Set{Union{}}}}
2649+
@testintersect(S, T, !Union{})
2650+
@test A <: typeintersect(S, T)
2651+
@test A <: typeintersect(T, S)
2652+
end

0 commit comments

Comments
 (0)