Skip to content

Commit 1e20630

Browse files
JeffBezansonKristofferC
authored andcommitted
fix #39948, stack overflow due to free typevar during jl_type_intersection2
(cherry picked from commit bbf14f8)
1 parent d06bab0 commit 1e20630

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/gf.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,9 @@ static int jl_type_intersection2(jl_value_t *t1, jl_value_t *t2, jl_value_t **is
15921592
return 0;
15931593
if (is_subty)
15941594
return 1;
1595+
// TODO: sometimes type intersection returns types with free variables
1596+
if (jl_has_free_typevars(t1) || jl_has_free_typevars(t2))
1597+
return 1;
15951598
// determine if type-intersection can be convinced to give a better, non-bad answer
15961599
// if the intersection was imprecise, see if we can do better by switching the types
15971600
*isect2 = jl_type_intersection(t2, t1);

test/subtype.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,3 +1878,10 @@ let A = Tuple{Type{<:Union{Number, T}}, Ref{T}} where T,
18781878
@test A == B
18791879
@test A <: B
18801880
end
1881+
1882+
# issue #39948
1883+
let A = Tuple{Array{Pair{T, JT} where JT<:Ref{T}, 1} where T, Vector},
1884+
I = typeintersect(A, Tuple{Vararg{Vector{T}}} where T)
1885+
@test_broken I <: A
1886+
@test_broken !Base.has_free_typevars(I)
1887+
end

0 commit comments

Comments
 (0)