From bbf14f842868fff7d395e8f81d02124de11180d1 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Mon, 8 Mar 2021 23:43:09 -0500 Subject: [PATCH] fix #39948, stack overflow due to free typevar during `jl_type_intersection2` --- src/gf.c | 3 +++ test/subtype.jl | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/gf.c b/src/gf.c index 0c2cd7472e0d0..c113211a0c7c6 100644 --- a/src/gf.c +++ b/src/gf.c @@ -1600,6 +1600,9 @@ static int jl_type_intersection2(jl_value_t *t1, jl_value_t *t2, jl_value_t **is return 0; if (is_subty) return 1; + // TODO: sometimes type intersection returns types with free variables + if (jl_has_free_typevars(t1) || jl_has_free_typevars(t2)) + return 1; // determine if type-intersection can be convinced to give a better, non-bad answer // if the intersection was imprecise, see if we can do better by switching the types *isect2 = jl_type_intersection(t2, t1); diff --git a/test/subtype.jl b/test/subtype.jl index 935cf0c244b9c..3c720dc4bf032 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -1894,3 +1894,10 @@ let T = Type{T} where T<:(AbstractArray{I}) where I<:(Base.IteratorsMD.Cartesian @test I <: S @test_broken I == typeintersect(S, T) end + +# issue #39948 +let A = Tuple{Array{Pair{T, JT} where JT<:Ref{T}, 1} where T, Vector}, + I = typeintersect(A, Tuple{Vararg{Vector{T}}} where T) + @test_broken I <: A + @test_broken !Base.has_free_typevars(I) +end