From 19949811ceab167862c4bbcbcfa413be11f754c8 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Fri, 23 Oct 2020 17:03:26 -0400 Subject: [PATCH] avoid forming circular lower bound in type intersection (#38114) fixes #37685, fixes #38081 --- src/subtype.c | 5 ++++- test/subtype.jl | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/subtype.c b/src/subtype.c index c9a6180e4a27c..34590492c11e2 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -2931,7 +2931,10 @@ static jl_value_t *intersect(jl_value_t *x, jl_value_t *y, jl_stenv_t *e, int pa jl_value_t *ub=NULL, *lb=NULL; JL_GC_PUSH2(&lb, &ub); ub = intersect_aside(xub, yub, e, 0, xx ? xx->depth0 : 0); - lb = simple_join(xlb, ylb); + if (xlb == y) + lb = ylb; + else + lb = simple_join(xlb, ylb); if (yy) { if (lb != y) yy->lb = lb; diff --git a/test/subtype.jl b/test/subtype.jl index be324df04e2f5..c987167a57712 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -1772,3 +1772,17 @@ end # issue #37255 @test Type{Union{}} == Type{T} where {Union{}<:T<:Union{}} + +# issue #38081 +struct AlmostLU{T, S<:AbstractMatrix{T}} +end +let X1 = Tuple{AlmostLU, Vector{T}} where T, + X2 = Tuple{AlmostLU{S, X} where X<:Matrix, Vector{S}} where S<:Union{Float32, Float64}, + I = typeintersect(X1, X2) + # TODO: the quality of this intersection is not great; for now just test that it + # doesn't stack overflow + @test I<:X1 || I<:X2 + actual = Tuple{AlmostLU{S, X} where X<:Matrix{S}, Vector{S}} where S<:Union{Float32, Float64} + @test I >: actual + @test_broken I == actual +end