Skip to content

IArray.toArray: Deprecate broken method #12598

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

Merged
merged 1 commit into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) = ""