Skip to content

Commit

Permalink
fix #32607, bug in typeintersect of X{<:Tuple1} vs. X{Tuple2} (#3…
Browse files Browse the repository at this point in the history
…2771)

(cherry picked from commit 4671ddc)
  • Loading branch information
JeffBezanson committed Aug 5, 2019
1 parent 2d8f4db commit a4104fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -2454,26 +2454,16 @@ static jl_value_t *intersect_invariant(jl_value_t *x, jl_value_t *y, jl_stenv_t
flip_vars(e);
return jl_bottom_type;
}
/*
TODO: This is a band-aid for issue #23685. A better solution would be to
first normalize types so that all `where` expressions in covariant position
are pulled out to the top level.
*/
if ((jl_is_typevar(x) && !jl_is_typevar(y) && lookup(e, (jl_tvar_t*)x) == NULL) ||
(jl_is_typevar(y) && !jl_is_typevar(x) && lookup(e, (jl_tvar_t*)y) == NULL))
return ii;
jl_value_t *root=NULL;
jl_savedenv_t se;
JL_GC_PUSH2(&ii, &root);
save_env(e, &root, &se);
if (!subtype_in_env(x, y, e)) {
if (!subtype_in_env_existential(x, y, e, 0, e->invdepth)) {
ii = NULL;
}
else {
flip_vars(e);
if (!subtype_in_env(y, x, e))
if (!subtype_in_env_existential(y, x, e, 0, e->invdepth))
ii = NULL;
flip_vars(e);
}
restore_env(e, root, &se);
free(se.buf);
Expand Down
11 changes: 11 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,17 @@ function test_intersection()
@test_broken typeintersect(Tuple{Type{Z},Z} where Z,
Tuple{Type{Ref{T}} where T, Ref{Float64}}) ==
Tuple{Type{Ref{Float64}},Ref{Float64}}

# issue #32607
@testintersect(Type{<:Tuple{Integer,Integer}},
Type{Tuple{Int,T}} where T,
Type{Tuple{Int,T}} where T<:Integer)
@testintersect(Type{<:Tuple{Any,Vararg{Any}}},
Type{Tuple{Vararg{Int,N}}} where N,
Type{Tuple{Int,Vararg{Int,N}}} where N)
@testintersect(Type{<:Array},
Type{AbstractArray{T}} where T,
Bottom)
end

function test_intersection_properties()
Expand Down

0 comments on commit a4104fb

Please sign in to comment.