Skip to content

in(x, ::StepRangeLen) fails when step is zero #41784

@barucden

Description

@barucden

Working on #41769, I found an error:

julia> r = StepRangeLen(3, 0, 5)
StepRangeLen(3, 0, 5)

julia> 3 in r
ERROR: DivideError: integer division error
Stacktrace:
 [1] div
   @ ./int.jl:278 [inlined]
 [2] div
   @ ./div.jl:257 [inlined]
 [3] div
   @ ./div.jl:302 [inlined]
 [4] fld
   @ ./div.jl:268 [inlined]
 [5] mod
   @ ./int.jl:270 [inlined]
 [6] in(x::Int64, r::StepRangeLen{Int64, Int64, Int64, Int64})
   @ Base ./range.jl:1346
 [7] top-level scope
   @ REPL[23]:1

This is because 3 is inside the range, and step(r) == 0 makes mod on this line fail.

Slightly related is #41402, which deals with a completely different problem, but eventually sees division error in mod. Perhaps mod should check the modulo and throw a better error too?

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueIndicates a good issue for first-time contributors to Julia

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions