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

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

Closed
barucden opened this issue Aug 4, 2021 · 3 comments · Fixed by #41974
Closed

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

barucden opened this issue Aug 4, 2021 · 3 comments · Fixed by #41974
Labels
good first issue Indicates a good issue for first-time contributors to Julia

Comments

@barucden
Copy link
Contributor

barucden commented Aug 4, 2021

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?

@martinholters
Copy link
Member

Just inserting a step(r) == 0 before the call to mod should do the trick. Similar for the AbstractChar method ('a' in StepRangeLen('a', 0, 5) fails, too.)

@martinholters martinholters added the good first issue Indicates a good issue for first-time contributors to Julia label Aug 18, 2021
@mohilkhare1708
Copy link

@martinholters I would like to work on this issue, kindly assign me this.

@martinholters
Copy link
Member

Just go ahead, no assignment needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Indicates a good issue for first-time contributors to Julia
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants