Skip to content

Commit

Permalink
Properly handle non-normalized vararg tuples in tuple_type_tail
Browse files Browse the repository at this point in the history
In preparation for #31681 in particular, but the problem exists on master
as well, we just tend to not encounter non-normalized tuple types that often.
  • Loading branch information
Keno committed Apr 18, 2019
1 parent 83b4409 commit 731ef41
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ function tuple_type_tail(T::Type)
else
T.name === Tuple.name || throw(MethodError(tuple_type_tail, (T,)))
if isvatuple(T) && length(T.parameters) == 1
return T
va = T.parameters[1]
(isa(va, DataType) && isa(va.parameters[2], Int)) || return T
return Tuple{Vararg{va.parameters[1], va.parameters[2]-1}}
end
return Tuple{argtail(T.parameters...)...}
end
Expand Down
3 changes: 3 additions & 0 deletions test/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,6 @@ end
@test map(p->getproperty(ttest, p), propertynames(ttest)) == ttest
@test_throws ErrorException setproperty!(ttest, 1, :d)
end

# tuple_type_tail on non-normalized vararg tuple
@test Base.tuple_type_tail(Tuple{Vararg{T, 3}} where T<:Real) == Tuple{Vararg{T, 2}} where T<:Real

0 comments on commit 731ef41

Please sign in to comment.