Skip to content

Commit 66c737e

Browse files
authored
Specify type signatures for CartesianIndices iteration states (#59328)
These methods are clearly meant to be used with a `CartesianIndex` state, and this PR makes this explicit.
1 parent fa4972d commit 66c737e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

base/multidimensional.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ module IteratorsMD
447447
end
448448
iterfirst, iterfirst
449449
end
450-
@inline function iterate(iter::CartesianIndices, state)
450+
@inline function iterate(iter::CartesianIndices, state::CartesianIndex)
451451
valid, I = __inc(state.I, iter.indices)
452452
valid || return nothing
453453
return CartesianIndex(I...), CartesianIndex(I...)
@@ -481,7 +481,7 @@ module IteratorsMD
481481
end
482482

483483
# 0-d cartesian ranges are special-cased to iterate once and only once
484-
iterate(iter::CartesianIndices{0}, done=false) = done ? nothing : (CartesianIndex(), true)
484+
iterate(iter::CartesianIndices{0}, done::Bool=false) = done ? nothing : (CartesianIndex(), true)
485485

486486
size(iter::CartesianIndices) = map(length, iter.indices)
487487

@@ -960,7 +960,7 @@ Fallback to `iterate` by default, but optimized for indices type in `Base`.
960960
_prechecked_iterate(iter::AbstractUnitRange, i = first(iter)) = i, convert(eltype(iter), i + step(iter))
961961
_prechecked_iterate(iter::LinearIndices, i = first(iter)) = i, i + 1
962962
_prechecked_iterate(iter::CartesianIndices) = first(iter), first(iter)
963-
function _prechecked_iterate(iter::CartesianIndices, i)
963+
function _prechecked_iterate(iter::CartesianIndices, i::CartesianIndex)
964964
i′ = IteratorsMD.inc(i.I, iter.indices)
965965
return i′, i′
966966
end

0 commit comments

Comments
 (0)