Skip to content

Commit f7d7665

Browse files
authored
Merge pull request #21192 from JuliaLang/mh/fix20626
Use `TypeVar`s in `limit_type_depth` in `Union`s in invariant position
2 parents 378ed8a + bb1facc commit f7d7665

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

base/inference.jl

+8-2
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,13 @@ end
670670
function limit_type_depth(t::ANY, d::Int, cov::Bool, vars::Vector{TypeVar}=TypeVar[])
671671
if isa(t,Union)
672672
if d > MAX_TYPE_DEPTH
673-
return Any
673+
if cov
674+
return Any
675+
else
676+
var = TypeVar(:_)
677+
push!(vars, var)
678+
return var
679+
end
674680
end
675681
return Union{limit_type_depth(t.a, d+1, cov, vars),
676682
limit_type_depth(t.b, d+1, cov, vars)}
@@ -2097,7 +2103,7 @@ function ⊑(a::ANY, b::ANY)
20972103
if isa(b, Const)
20982104
return a.val === b.val
20992105
end
2100-
return isa(a.val, b)
2106+
return isa(a.val, widenconst(b))
21012107
elseif isa(b, Const)
21022108
return a === Bottom
21032109
elseif !(isa(a, Type) || isa(a, TypeVar)) ||

test/inference.jl

+5
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,11 @@ let A = 1:2, z = zip(A, A, A, A, A, A, A, A, A, A, A, A)
655655
@test z isa Core.Inference.limit_type_depth(typeof(z), 0)
656656
@test start(z) == (1, (1, (1, (1, (1, (1, (1, (1, (1, (1, (1, 1)))))))))))
657657
end
658+
# introduce TypeVars in Unions in invariant position
659+
let T = Val{Val{Val{Union{Int8,Int16,Int32,Int64,UInt8,UInt16,UInt32,UInt64}}}}
660+
#TODO: this test hits an assertion (see #21191)
661+
#@test T <: Core.Inference.limit_type_depth(T, 0)
662+
end
658663

659664
# issue #20704
660665
f20704(::Int) = 1

0 commit comments

Comments
 (0)