Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix an invariance bug in limit_type_depth. part of #23786 #23800

Merged
merged 1 commit into from
Sep 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ function limit_type_depth(@nospecialize(t), d::Int, cov::Bool, vars::Vector{Type
end
ub = Any
else
ub = limit_type_depth(v.ub, d - 1, true)
ub = limit_type_depth(v.ub, d - 1, cov, vars)
end
if v.lb === Bottom || type_depth(v.lb) > d
# note: lower bounds need to be widened by making them lower
Expand All @@ -855,7 +855,8 @@ function limit_type_depth(@nospecialize(t), d::Int, cov::Bool, vars::Vector{Type
if d < 0
if isvarargtype(t)
# never replace Vararg with non-Vararg
return Vararg{limit_type_depth(P[1], d, cov, vars), P[2]}
# passing depth=0 avoids putting a bare typevar here, for the diagonal rule
return Vararg{limit_type_depth(P[1], 0, cov, vars), P[2]}
end
widert = t.name.wrapper
if !(t <: widert)
Expand All @@ -870,7 +871,11 @@ function limit_type_depth(@nospecialize(t), d::Int, cov::Bool, vars::Vector{Type
return var
end
stillcov = cov && (t.name === Tuple.name)
Q = map(x -> limit_type_depth(x, d - 1, stillcov, vars), P)
newdepth = d - 1
if isvarargtype(t)
newdepth = max(newdepth, 0)
end
Q = map(x -> limit_type_depth(x, newdepth, stillcov, vars), P)
R = t.name.wrapper{Q...}
if cov && !stillcov
for var in vars
Expand Down
7 changes: 7 additions & 0 deletions test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1218,3 +1218,10 @@ let c(::Type{T}, x) where {T<:Array} = T,
f() = c(Vector{Any[Int][1]}, [1])
@test f() === Vector{Int}
end

# issue #23786
struct T23786{D<:Tuple{Vararg{Vector{T} where T}}, N}
end
let t = Tuple{Type{T23786{D, N} where N where D<:Tuple{Vararg{Array{T, 1} where T, N} where N}}}
@test Core.Inference.limit_type_depth(t, 4) >: t
end