Skip to content

Commit

Permalink
fix method signature for one of the Tuple constructors (#31160)
Browse files Browse the repository at this point in the history
from #31112
  • Loading branch information
JeffBezanson committed Mar 7, 2019
1 parent 7f86715 commit 735e7b5
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions base/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,6 @@ if nameof(@__MODULE__) === :Base

(::Type{T})(x::Tuple) where {T<:Tuple} = convert(T, x) # still use `convert` for tuples

# resolve ambiguity between preceding and following methods
All16{E,N}(x::Tuple) where {E,N} = convert(All16{E,N}, x)

function (T::All16{E,N})(itr) where {E,N}
len = N+16
elts = collect(E, Iterators.take(itr,len))
if length(elts) != len
_totuple_err(T)
end
(elts...,)
end

(::Type{T})(itr) where {T<:Tuple} = _totuple(T, itr)

_totuple(::Type{Tuple{}}, itr, s...) = ()
Expand All @@ -231,6 +219,16 @@ function _totuple(T, itr, s...)
(convert(tuple_type_head(T), y[1]), _totuple(tuple_type_tail(T), itr, y[2])...)
end

# use iterative algorithm for long tuples
function _totuple(T::Type{All16{E,N}}, itr) where {E,N}
len = N+16
elts = collect(E, Iterators.take(itr,len))
if length(elts) != len
_totuple_err(T)
end
(elts...,)
end

_totuple(::Type{Tuple{Vararg{E}}}, itr, s...) where {E} = (collect(E, Iterators.rest(itr,s...))...,)

_totuple(::Type{Tuple}, itr, s...) = (collect(Iterators.rest(itr,s...))...,)
Expand Down

0 comments on commit 735e7b5

Please sign in to comment.