From 679477813eab875619ba881863c4a2db11f116d6 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Fri, 28 Sep 2018 13:51:02 -0400 Subject: [PATCH] fix #29208, incorrect `Union{}` result from type intersection (#29380) also fixes #29357 --- src/subtype.c | 16 +++++++++------- test/subtype.jl | 10 ++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/subtype.c b/src/subtype.c index 78f280db677c8..e4584fb6d0130 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -1392,13 +1392,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)) { diff --git a/test/subtype.jl b/test/subtype.jl index b2e710ed99ce9..943e8c48d4898 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -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,