Skip to content

Commit 53ffe56

Browse files
authored
typeintersect: more fastpath to skip intersect under circular env (#56304)
fix #56040
1 parent 894296b commit 53ffe56

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/subtype.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -2464,8 +2464,10 @@ static jl_value_t *intersect_aside(jl_value_t *x, jl_value_t *y, jl_stenv_t *e,
24642464
return y;
24652465
if (y == (jl_value_t*)jl_any_type && !jl_is_typevar(x))
24662466
return x;
2467-
// band-aid for #46736
2468-
if (obviously_egal(x, y))
2467+
// band-aid for #46736 #56040
2468+
if (obviously_in_union(x, y))
2469+
return y;
2470+
if (obviously_in_union(y, x))
24692471
return x;
24702472

24712473
jl_varbinding_t *vars = NULL;
@@ -2495,6 +2497,9 @@ static jl_value_t *intersect_aside(jl_value_t *x, jl_value_t *y, jl_stenv_t *e,
24952497

24962498
static jl_value_t *intersect_union(jl_value_t *x, jl_uniontype_t *u, jl_stenv_t *e, int8_t R, int param)
24972499
{
2500+
// band-aid for #56040
2501+
if (!jl_is_uniontype(x) && obviously_in_union((jl_value_t *)u, x))
2502+
return x;
24982503
int no_free = !jl_has_free_typevars(x) && !jl_has_free_typevars((jl_value_t*)u);
24992504
if (param == 2 || no_free) {
25002505
jl_value_t *a=NULL, *b=NULL;

test/subtype.jl

+9
Original file line numberDiff line numberDiff line change
@@ -2721,3 +2721,12 @@ let T1 = NTuple{12, Union{Val{1}, Val{2}, Val{3}, Val{4}, Val{5}, Val{6}}}
27212721
@test !(T1 <: T2)
27222722
@test Tuple{Union{Val{1},Val{2}}} <: Tuple{S} where {T, S<:Val{T}}
27232723
end
2724+
2725+
#issue 56040
2726+
let S = Dict{V,V} where {V},
2727+
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}}},
2728+
A = Dict{Ref{Set{Union{}}}, Ref{Set{Union{}}}}
2729+
@testintersect(S, T, !Union{})
2730+
@test A <: typeintersect(S, T)
2731+
@test A <: typeintersect(T, S)
2732+
end

0 commit comments

Comments
 (0)