Skip to content

Commit

Permalink
Add safe-init test to prevent adding cold elements to hot arrays
Browse files Browse the repository at this point in the history
This adds a negative test to ensure that the initialization checker does
nt allow cold values to be inserted into hot arrays through a method
call.
  • Loading branch information
Xavientois committed Apr 12, 2022
1 parent f3cca47 commit 8a1adb2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/init/neg/cold-insert-hot-array.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
object A:
def foo[T](x: T, array: Array[T]): Unit = array(0) = x

class B {
var a = new Array[B](2)
A.foo(this, a)
println(a(0).i)
val i = 99
}

0 comments on commit 8a1adb2

Please sign in to comment.