Skip to content

Commit b378843

Browse files
committed
More tests for array
1 parent c137c21 commit b378843

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

compiler/src/dotty/tools/dotc/transform/init/Objects.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,9 @@ object Objects:
719719
// The outer can be a bottom value for top-level classes.
720720

721721
if klass == defn.ArrayClass then
722-
OfArray(State.currentObject)
722+
val arr = OfArray(State.currentObject)
723+
Heap.write(arr.addr, Bottom)
724+
arr
723725
else
724726
// Widen the outer to finitize the domain. Arguments already widened in `evalArgs`.
725727
val (outerWidened, envWidened) =
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import scala.annotation.init
2+
3+
class Box(x: Int):
4+
def foo(): Int = 100
5+
6+
object A:
7+
val array: Array[Box] = new Array(1)
8+
val n = array(0).foo() // ok, no crash
9+
10+
object B:
11+
var y = A.array(0).foo() * 2 // error
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.annotation.init
2+
3+
class Box(x: Int):
4+
def foo(): Int = 100
5+
6+
object A:
7+
val array: Array[Box] = new Array(1)
8+
array(0) = new Box(10): @init.expose
9+
val n = array(0).foo() // ok
10+
11+
object B:
12+
var y = A.array(0).foo() * 2 // error

0 commit comments

Comments
 (0)