bug
bug copied to clipboard
Wide NumericRange.iterator could avoid `IllegalArgumentException: More than Int.MaxValue elements.`
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 https://github.com/scala/scala/pull/10259, NumericRangeIterator could possible be reworked in terns of crossesTheEndAfterN to avoid calling length and tripping the exception