Skip to content

Commit 37692da

Browse files
Xavientoisolhotak
authored andcommitted
Add safe-init test to prevent adding cold elements to hot arrays
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.
1 parent 34261df commit 37692da

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object A:
2+
def foo[T](x: T, array: Array[T]): Unit = array(0) = x
3+
4+
class B {
5+
var a = new Array[B](2)
6+
A.foo(this, a) //error
7+
println(a(0).i)
8+
val i = 99
9+
}

0 commit comments

Comments
 (0)