From 8a1adb2c2f5cdc3ef1f2746bf89019b906ea8546 Mon Sep 17 00:00:00 2001 From: Xavientois Date: Fri, 8 Apr 2022 13:08:58 -0400 Subject: [PATCH] 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. --- tests/init/neg/cold-insert-hot-array.scala | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tests/init/neg/cold-insert-hot-array.scala diff --git a/tests/init/neg/cold-insert-hot-array.scala b/tests/init/neg/cold-insert-hot-array.scala new file mode 100644 index 000000000000..9a7239ec2a06 --- /dev/null +++ b/tests/init/neg/cold-insert-hot-array.scala @@ -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 +} \ No newline at end of file