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
Ranges bigger than Int.MaxValue are not always rejected, result in empty NumericRange #4308
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4308?orig=1 |
@dcsobral said: |
@soc said:
Both should behave the same and throw an exception instead of returning a wrong result silently. |
@soc said: The bug is in NumericRange.count: 193 val longCount: Long =
194 if (start == end) { if (isInclusive) 1 else 0 }
195 else if (end > start != step > zero) 0
196 else {
197 val jumps = toLong((end - start) / step) // <-------
198 val remainder = toLong((end - start) % step)
199
200 if (!isInclusive && zero == remainder) jumps
201 else jumps + 1L
202 }
203
204 if (longCount > scala.Int.MaxValue || longCount < 0L)
205 throw new IllegalArgumentException("Seqs cannot contain more than Int.MaxValue elements.") |
=== What steps will reproduce the problem ===
=== What is the expected behavior? ===
(Probably)
=== What do you see instead? ===
=== Additional information ===
Very likely related to #3232.
It would be a good idea to think about how to better test these things. I guess this Range bug won't be the last ...
=== What versions of the following are you using? ===
The text was updated successfully, but these errors were encountered: