Skip to content

Commit c8f4ad2

Browse files
committed
fix #32607, bug in typeintersect of X{<:Tuple1} vs. X{Tuple2}
1 parent 86c2126 commit c8f4ad2

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
@@ -2683,26 +2683,16 @@ static jl_value_t *intersect_invariant(jl_value_t *x, jl_value_t *y, jl_stenv_t
26832683
flip_vars(e);
26842684
return jl_bottom_type;
26852685
}
2686-
/*
2687-
TODO: This is a band-aid for issue #23685. A better solution would be to
2688-
first normalize types so that all `where` expressions in covariant position
2689-
are pulled out to the top level.
2690-
*/
2691-
if ((jl_is_typevar(x) && !jl_is_typevar(y) && lookup(e, (jl_tvar_t*)x) == NULL) ||
2692-
(jl_is_typevar(y) && !jl_is_typevar(x) && lookup(e, (jl_tvar_t*)y) == NULL))
2693-
return ii;
26942686
jl_value_t *root=NULL;
26952687
jl_savedenv_t se;
26962688
JL_GC_PUSH2(&ii, &root);
26972689
save_env(e, &root, &se);
2698-
if (!subtype_in_env(x, y, e)) {
2690+
if (!subtype_in_env_existential(x, y, e, 0, e->invdepth)) {
26992691
ii = NULL;
27002692
}
27012693
else {
2702-
flip_vars(e);
2703-
if (!subtype_in_env(y, x, e))
2694+
if (!subtype_in_env_existential(y, x, e, 0, e->invdepth))
27042695
ii = NULL;
2705-
flip_vars(e);
27062696
}
27072697
restore_env(e, root, &se);
27082698
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)