Skip to content

Wide NumericRange.iterator could avoid IllegalArgumentException: More than Int.MaxValue elements. #13100

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

Open
retronym opened this issue Apr 29, 2025 · 0 comments

Comments

@retronym
Copy link
Member

Reproduction steps

Scala version: 2.13.16

scala> try { ((0L).until(Int.MaxValue.toLong + 1)).iterator } catch { case ex: IllegalArgumentException => ex.printStackTrace }
java.lang.IllegalArgumentException: More than Int.MaxValue elements.
	at scala.collection.immutable.NumericRange$.check$1(NumericRange.scala:433)
	at scala.collection.immutable.NumericRange$.count(NumericRange.scala:443)
	at scala.collection.immutable.NumericRange.length$lzycompute(NumericRange.scala:76)
	at scala.collection.immutable.NumericRange.length(NumericRange.scala:76)
	at scala.collection.immutable.NumericRange.last(NumericRange.scala:84)
	at scala.collection.immutable.NumericRange$NumericRangeIterator.<init>(NumericRange.scala:530)
	at scala.collection.immutable.NumericRange.iterator(NumericRange.scala:56)

Problem

In the spirit of the fix in scala/scala#10259, NumericRangeIterator could possible be reworked in terns of crossesTheEndAfterN to avoid calling length and tripping the exception

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant