Skip to content

uncaught iterate overflow for StepRange #37876

@johnnychen94

Description

@johnnychen94

I believe this overflow is unwanted.

julia> I = 1:2:typemax(Int)
1:2:9223372036854775807

julia> iterate(I, last(I))

julia> iterate(I, last(I)-1)
(-9223372036854775808, -9223372036854775808)

julia> iterate(I, last(I)-2)
(9223372036854775807, 9223372036854775807)

Another behavior that might be related to this:

julia> iterate(Base.OneTo(5), 6)
(7, 7)

Should this return nothing or (7, 7)?

Related lines are:

julia/base/range.jl

Lines 651 to 664 in 9392bbe

function iterate(r::Union{LinRange,StepRangeLen}, i::Int=1)
@_inline_meta
length(r) < i && return nothing
unsafe_getindex(r, i), i + 1
end
iterate(r::OrdinalRange) = isempty(r) ? nothing : (first(r), first(r))
function iterate(r::OrdinalRange{T}, i) where {T}
@_inline_meta
i == last(r) && return nothing
next = convert(T, i + step(r))
(next, next)
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions