Skip to content

Commit

Permalink
Merge pull request #12598 from dotty-staging/fix-toArray
Browse files Browse the repository at this point in the history
IArray.toArray: Deprecate broken method
  • Loading branch information
smarter authored May 25, 2021
2 parents 17a6ab0 + 4cfb637 commit 8f3fdf5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 5 additions & 3 deletions library/src/scala/IArray.scala
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,11 @@ object IArray:
extension [T](arr: IArray[T]) def takeWhile(p: T => Boolean): IArray[T] =
genericArrayOps(arr).takeWhile(p)

/** Returns a mutable copy of this immutable array. */
extension [T](arr: IArray[T]) def toArray: Array[T] =
arr.clone.asInstanceOf[Array[T]]
extension [T](arr: IArray[T])
/** Returns a mutable copy of this immutable array. */
@deprecated("This method implementation is incorrect and calling it can crash your program, please use `IArray.genericWrapArray(myIArray).toArray` instead.", "3.0.1")
def toArray: Array[T] =
arr.clone.asInstanceOf[Array[T]]

extension [T](arr: IArray[T])
def ++[U >: T: ClassTag](suffix: IArray[U]): IArray[U] = genericArrayOps(arr) ++ suffix.toSeq
Expand Down
5 changes: 5 additions & 0 deletions tests/neg-custom-args/deprecation/i12597.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@main def Test =
val a: IArray[Int] = IArray(2)
val b: IArray[Any] = a
val c = b.toArray // error: deprecated
c(0) = ""
5 changes: 5 additions & 0 deletions tests/run/i12597.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@main def Test =
val a: IArray[Int] = IArray(2)
val b: IArray[Any] = a
val c = IArray.genericWrapArray(b).toArray
c(0) = ""

0 comments on commit 8f3fdf5

Please sign in to comment.