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

Require all tuples in eachindex to have the same length. #48125

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 3 additions & 6 deletions base/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,9 @@ nextind(@nospecialize(t::Tuple), i::Integer) = Int(i)+1

function keys(t::Tuple, t2::Tuple...)
@inline
OneTo(_maxlength(t, t2...))
end
_maxlength(t::Tuple) = length(t)
function _maxlength(t::Tuple, t2::Tuple, t3::Tuple...)
@inline
max(length(t), _maxlength(t2, t3...))
lent = length(t)
all(x->length(x) == lent, t2) || throw_eachindex_mismatch_indices(IndexLinear(), t, t2...)
Base.OneTo(lent)
end

# this allows partial evaluation of bounded sequences of next() calls on tuples,
Expand Down
2 changes: 1 addition & 1 deletion test/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ end
@test iterate(t, y3[2]) === nothing

@test eachindex((2,5,"foo")) === Base.OneTo(3)
@test eachindex((2,5,"foo"), (1,2,5,7)) === Base.OneTo(4)
@test_throws DimensionMismatch eachindex((2,5,"foo"), (1,2,5,7))
end


Expand Down