Skip to content

Commit

Permalink
Merge pull request #21907 from JuliaLang/jb/fix21848
Browse files Browse the repository at this point in the history
fix #21848, bug in widening done by limit_type_depth
  • Loading branch information
JeffBezanson authored May 17, 2017
2 parents 4a99ce4 + f46ba0a commit 64a230b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
15 changes: 13 additions & 2 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,19 @@ function limit_type_depth(t::ANY, d::Int, cov::Bool, vars::Vector{TypeVar}=TypeV
P = t.parameters
isempty(P) && return t
if d > MAX_TYPE_DEPTH
cov && return t.name.wrapper
var = TypeVar(:_, t.name.wrapper)
if isvarargtype(t)
# never replace Vararg with non-Vararg
return Vararg{limit_type_depth(P[1], d, cov, vars), P[2]}
end
widert = t.name.wrapper
if !(t <: widert)
# This can happen when a typevar has bounds too wide for its context, e.g.
# `Complex{T} where T` is not a subtype of `Complex`. In that case widen even
# faster to something safe to ensure the result is a supertype of the input.
widert = Any
end
cov && return widert
var = TypeVar(:_, widert)
push!(vars, var)
return var
end
Expand Down
11 changes: 11 additions & 0 deletions test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -777,3 +777,14 @@ function break_21369()
end
end
@test_throws ErrorException break_21369() # not TypeError

# issue #21848
@test Core.Inference.limit_type_depth(Ref{Complex{T} where T}, Core.Inference.MAX_TYPE_DEPTH) == Ref
let T = Tuple{Tuple{Int64, Void},
Tuple{Tuple{Int64, Void},
Tuple{Int64, Tuple{Tuple{Int64, Void},
Tuple{Tuple{Int64, Void}, Tuple{Int64, Tuple{Tuple{Int64, Void}, Tuple{Tuple, Tuple}}}}}}}}
@test Core.Inference.limit_type_depth(T, 0) >: T
@test Core.Inference.limit_type_depth(T, 1) >: T
@test Core.Inference.limit_type_depth(T, 2) >: T
end

0 comments on commit 64a230b

Please sign in to comment.