Skip to content

Commit a4104fb

Browse files
committed
fix #32607, bug in typeintersect of X{<:Tuple1} vs. X{Tuple2} (#32771)
(cherry picked from commit 4671ddc)
1 parent 2d8f4db commit a4104fb

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/subtype.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,26 +2454,16 @@ static jl_value_t *intersect_invariant(jl_value_t *x, jl_value_t *y, jl_stenv_t
24542454
flip_vars(e);
24552455
return jl_bottom_type;
24562456
}
2457-
/*
2458-
TODO: This is a band-aid for issue #23685. A better solution would be to
2459-
first normalize types so that all `where` expressions in covariant position
2460-
are pulled out to the top level.
2461-
*/
2462-
if ((jl_is_typevar(x) && !jl_is_typevar(y) && lookup(e, (jl_tvar_t*)x) == NULL) ||
2463-
(jl_is_typevar(y) && !jl_is_typevar(x) && lookup(e, (jl_tvar_t*)y) == NULL))
2464-
return ii;
24652457
jl_value_t *root=NULL;
24662458
jl_savedenv_t se;
24672459
JL_GC_PUSH2(&ii, &root);
24682460
save_env(e, &root, &se);
2469-
if (!subtype_in_env(x, y, e)) {
2461+
if (!subtype_in_env_existential(x, y, e, 0, e->invdepth)) {
24702462
ii = NULL;
24712463
}
24722464
else {
2473-
flip_vars(e);
2474-
if (!subtype_in_env(y, x, e))
2465+
if (!subtype_in_env_existential(y, x, e, 0, e->invdepth))
24752466
ii = NULL;
2476-
flip_vars(e);
24772467
}
24782468
restore_env(e, root, &se);
24792469
free(se.buf);

test/subtype.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,17 @@ function test_intersection()
991991
@test_broken typeintersect(Tuple{Type{Z},Z} where Z,
992992
Tuple{Type{Ref{T}} where T, Ref{Float64}}) ==
993993
Tuple{Type{Ref{Float64}},Ref{Float64}}
994+
995+
# issue #32607
996+
@testintersect(Type{<:Tuple{Integer,Integer}},
997+
Type{Tuple{Int,T}} where T,
998+
Type{Tuple{Int,T}} where T<:Integer)
999+
@testintersect(Type{<:Tuple{Any,Vararg{Any}}},
1000+
Type{Tuple{Vararg{Int,N}}} where N,
1001+
Type{Tuple{Int,Vararg{Int,N}}} where N)
1002+
@testintersect(Type{<:Array},
1003+
Type{AbstractArray{T}} where T,
1004+
Bottom)
9941005
end
9951006

9961007
function test_intersection_properties()

0 commit comments

Comments
 (0)