Closed
Description
Reproduction steps
Given a wide NumericRange
, say BigInt(0) until (BigInt(Int.MaxValue) + 1000)
, if you try to take some amount from the range, or drop some from it, it causes IllegalArgumentException
. question on stackoverflow
Scala version: 3.x, 2.13.x
scala> val range = BigInt(0) until (BigInt(Int.MaxValue) + 1000)
val range: scala.collection.immutable.NumericRange.Exclusive[scala.math.BigInt] = NumericRange 0 until 2147484647
scala> range.take(2)
java.lang.IllegalArgumentException: More than Int.MaxValue elements.
at scala.collection.immutable.NumericRange$.check$1(NumericRange.scala:324)
at scala.collection.immutable.NumericRange$.count(NumericRange.scala:334)
at scala.collection.immutable.NumericRange.length$lzycompute(NumericRange.scala:75)
at scala.collection.immutable.NumericRange.length(NumericRange.scala:75)
at scala.collection.immutable.NumericRange.take(NumericRange.scala:143)
... 32 elided
scala> range.drop(Int.MaxValue)
java.lang.IllegalArgumentException: More than Int.MaxValue elements.
at scala.collection.immutable.NumericRange$.check$1(NumericRange.scala:324)
at scala.collection.immutable.NumericRange$.count(NumericRange.scala:334)
at scala.collection.immutable.NumericRange.length$lzycompute(NumericRange.scala:75)
at scala.collection.immutable.NumericRange.length(NumericRange.scala:75)
at scala.collection.immutable.NumericRange.drop(NumericRange.scala:149)
... 32 elided
Problem
The problem is the unexpected behavior of the range. It's the fact that you are able to create a wide range, but you can not take a small piece of it.