Skip to content

Commit

Permalink
fix #39948, stack overflow due to free typevar during `jl_type_inters…
Browse files Browse the repository at this point in the history
…ection2`

(cherry picked from commit bbf14f8)
  • Loading branch information
JeffBezanson authored and KristofferC committed Mar 9, 2021
1 parent d06bab0 commit 1e20630
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,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);
Expand Down
7 changes: 7 additions & 0 deletions test/subtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1878,3 +1878,10 @@ let A = Tuple{Type{<:Union{Number, T}}, Ref{T}} where T,
@test A == B
@test A <: B
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

0 comments on commit 1e20630

Please sign in to comment.