Skip to content

Commit a452acc

Browse files
navdeeprananavdeep ranaoscardssmithMoelfadienes
authored
Require all tuples in eachindex to have the same length. (#48125)
Potential fix for #47898 --------- Co-authored-by: navdeep rana <navdeepr@tifrh.res.in> Co-authored-by: Oscar Smith <oscardssmith@gmail.com> Co-authored-by: Jerry Ling <proton@jling.dev> Co-authored-by: Andy Dienes <51664769+adienes@users.noreply.github.com>
1 parent 1998d5b commit a452acc

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

base/tuple.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,9 @@ nextind(@nospecialize(t::Tuple), i::Integer) = Int(i)+1
149149

150150
function keys(t::Tuple, t2::Tuple...)
151151
@inline
152-
OneTo(_maxlength(t, t2...))
153-
end
154-
_maxlength(t::Tuple) = length(t)
155-
function _maxlength(t::Tuple, t2::Tuple, t3::Tuple...)
156-
@inline
157-
max(length(t), _maxlength(t2, t3...))
152+
lent = length(t)
153+
all(x->length(x) == lent, t2) || throw_eachindex_mismatch_indices(IndexLinear(), t, t2...)
154+
Base.OneTo(lent)
158155
end
159156

160157
# this allows partial evaluation of bounded sequences of next() calls on tuples,

test/tuple.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ end
208208
@test iterate(t, y3[2]) === nothing
209209

210210
@test eachindex((2,5,"foo")) === Base.OneTo(3)
211-
@test eachindex((2,5,"foo"), (1,2,5,7)) === Base.OneTo(4)
211+
@test_throws DimensionMismatch eachindex((2,5,"foo"), (1,2,5,7))
212212

213213
@test Core.Compiler.is_nothrow(Base.infer_effects(iterate, (Tuple{Int,Int,Int}, Int)))
214214
end

0 commit comments

Comments
 (0)