Skip to content

Commit

Permalink
fix #29208, incorrect Union{} result from type intersection (#29380)
Browse files Browse the repository at this point in the history
also fixes #29357

(cherry picked from commit 6794778)
  • Loading branch information
JeffBezanson authored and KristofferC committed Sep 30, 2018
1 parent 63384f3 commit 8cc9136
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/subtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -1379,13 +1379,15 @@ static jl_value_t *intersect_var(jl_tvar_t *b, jl_value_t *a, jl_stenv_t *e, int
if (param == 2) {
jl_value_t *ub = R ? intersect_ufirst(a, bb->ub, e, d) : intersect_ufirst(bb->ub, a, e, d);
JL_GC_PUSH2(&ub, &root);
save_env(e, &root, &se);
int issub = subtype_in_env(bb->lb, ub, e);
restore_env(e, root, &se);
free(se.buf);
if (!issub) {
JL_GC_POP();
return jl_bottom_type;
if (!jl_has_free_typevars(ub) && !jl_has_free_typevars(bb->lb)) {
save_env(e, &root, &se);
int issub = subtype_in_env(bb->lb, ub, e);
restore_env(e, root, &se);
free(se.buf);
if (!issub) {
JL_GC_POP();
return jl_bottom_type;
}
}
if (ub != (jl_value_t*)b) {
if (jl_has_free_typevars(ub)) {
Expand Down
10 changes: 10 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,16 @@ function test_intersection()
@testintersect(Tuple{Ref{Ref{T}} where T, Ref},
Tuple{Ref{T}, Ref{T}} where T,
Tuple{Ref{Ref{T}}, Ref{Ref{T}}} where T)
# issue #29208
@testintersect(Tuple{Ref{Ref{T}} where T, Ref{Ref{Int}}},
Tuple{Ref{T}, Ref{T}} where T,
Tuple{Ref{Ref{Int}}, Ref{Ref{Int}}})
@testintersect(Tuple{Vector{Pair{K,V}}, Vector{Pair{K,V}}} where K where V,
Tuple{(Array{Pair{Ref{_2},_1},1} where _2 where _1),
Array{Pair{Ref{Int64},Rational{Int64}},1}},
Tuple{Vector{Pair{Ref{Int64},Rational{Int64}}},
Vector{Pair{Ref{Int64},Rational{Int64}}}})
@testintersect(Vector{>:Missing}, Vector{Int}, Union{})

# issue #23685
@testintersect(Pair{Type{Z},Z} where Z,
Expand Down

0 comments on commit 8cc9136

Please sign in to comment.