From 8653aedddd56bc0b5b31799d4eadf26ac39885f8 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 8 May 2019 14:38:34 -0400 Subject: [PATCH] fix #31899, type intersection involving Int in upper bound (#31960) (cherry picked from commit 4c28b3685c88eefef029e66b7b48fd1a880c6103) --- src/subtype.c | 7 ++++++- test/subtype.jl | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/subtype.c b/src/subtype.c index 9476833f44c58..0ea4e3d4b3a87 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -975,6 +975,8 @@ static int subtype(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int param) return var_gt((jl_tvar_t*)y, x, e, param); if (y == (jl_value_t*)jl_any_type && !jl_has_free_typevars(x)) return 1; + if (x == jl_bottom_type && !jl_has_free_typevars(y)) + return 1; jl_value_t *ux = jl_unwrap_unionall(x); jl_value_t *uy = jl_unwrap_unionall(y); if ((x != ux || y != uy) && y != (jl_value_t*)jl_any_type && jl_is_datatype(ux) && jl_is_datatype(uy) && @@ -1774,7 +1776,10 @@ static jl_value_t *finish_unionall(jl_value_t *res JL_MAYBE_UNROOTED, jl_varbind jl_tvar_t *newvar = vb->var; JL_GC_PUSH2(&res, &newvar); // try to reduce var to a single value - if (obviously_egal(vb->lb, vb->ub)) { + if (jl_is_long(vb->ub) && jl_is_typevar(vb->lb)) { + varval = vb->ub; + } + else if (obviously_egal(vb->lb, vb->ub)) { // given x<:T<:x, substitute x for T varval = vb->ub; } diff --git a/test/subtype.jl b/test/subtype.jl index d301064239054..b93df90128b0f 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -1506,3 +1506,23 @@ let A = typeintersect(HFPotential, T), @test A == B == HFPotential{kind,Float64,Any,Applied{Int,Tuple{ApplyQuasiArray{Float64,2,Applied{Int,Tuple{Any,BandedMatrix{Int,Ones{Int,2,Tuple{OneTo{Int},OneTo{Int}}},OneTo{Int}}}}},Diagonal{Float64,Array{Float64,1}},ApplyQuasiArray{Float64,2,Applied{Int,Tuple{Adjoint{Int,BandedMatrix{Int,Ones{Int,2,Tuple{OneTo{Int},OneTo{Int}}},OneTo{Int}}},QuasiAdjoint{Float64,Any}}}}}},P} where P<:Integer where kind end end + +# issue #31899 +struct SA{N,L} +end +@testintersect(Tuple{Type{SA{Int, L} where L}, Type{SA{Int, Int8}}}, + Tuple{Type{<:SA{N, L}}, Type{<:SA{N, L}}} where {N,L}, + Union{}) +@testintersect(Tuple{Type{SA{2, L} where L}, Type{SA{2, 16}}}, + Tuple{Type{<:SA{N, L}}, Type{<:SA{N, L}}} where {L,N}, + Union{}) +@testintersect(Tuple{Type{SA{2, L} where L}, Type{SA{2, 16}}}, + Tuple{Type{<:SA{N, L}}, Type{<:SA{N, L}}} where {N,L}, + Union{}) +@testintersect(Tuple{Type{SA{2, L}}, Type{SA{2, L}}} where L, + Tuple{Type{<:SA{N, L}}, Type{<:SA{N, L}}} where {N,L}, + Tuple{Type{SA{2, L}}, Type{SA{2, L}}} where L) +@testintersect(Tuple{Type{SA{2, L}}, Type{SA{2, 16}}} where L, + Tuple{Type{<:SA{N, L}}, Type{<:SA{N, L}}} where {N,L}, + # TODO: this could be narrower + Tuple{Type{SA{2, L}}, Type{SA{2, 16}}} where L)