|
1 | 1 | package scala
|
2 | 2 | import reflect.ClassTag
|
3 | 3 |
|
| 4 | +import scala.annotation.experimental |
4 | 5 | import scala.collection.{LazyZip2, SeqView, Searching, Stepper, StepperShape}
|
5 | 6 | import scala.collection.immutable.ArraySeq
|
6 | 7 | import scala.collection.mutable.{ArrayBuilder, Builder}
|
@@ -249,9 +250,18 @@ object IArray:
|
249 | 250 | extension [T](arr: IArray[T]) def takeWhile(p: T => Boolean): IArray[T] =
|
250 | 251 | genericArrayOps(arr).takeWhile(p)
|
251 | 252 |
|
252 |
| - /** Returns a mutable copy of this immutable array. */ |
253 |
| - extension [T](arr: IArray[T]) def toArray: Array[T] = |
254 |
| - arr.clone.asInstanceOf[Array[T]] |
| 253 | + // NOTE: these two overloads are never selected when calling toArray on an |
| 254 | + // IArray because they're considered ambiguous, but such calls still typecheck |
| 255 | + // because of the implicit conversion `genericWrapArray`. |
| 256 | + extension [T](arr: IArray[T]) |
| 257 | + /** Returns a mutable copy of this immutable array. */ |
| 258 | + @deprecated("This method implementation is incorrect and calling it can crash your program, please use the other overload.", "3.0.1") |
| 259 | + def toArray: Array[T] = |
| 260 | + arr.clone.asInstanceOf[Array[T]] |
| 261 | + /** Returns a mutable copy of this immutable array. */ |
| 262 | + @experimental |
| 263 | + def toArray[U >: T: ClassTag]: Array[U] = |
| 264 | + Array.copyAs(arr, arr.length) |
255 | 265 |
|
256 | 266 | extension [T](arr: IArray[T])
|
257 | 267 | def ++[U >: T: ClassTag](suffix: IArray[U]): IArray[U] = genericArrayOps(arr) ++ suffix.toSeq
|
|
0 commit comments