From f7329b4e63f78046933d5ab7882998a73df563e4 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Tue, 20 Oct 2020 15:01:32 -0400 Subject: [PATCH] avoid forming circular lower bound in type intersection fixes #37685, fixes #38081 --- src/subtype.c | 5 ++++- test/subtype.jl | 11 +++++++++++ 2 files changed, 15 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..cde75e94404a0 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -1772,3 +1772,14 @@ 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 +end