File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed
compiler/src/dotty/tools/dotc/transform/init Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -719,7 +719,9 @@ object Objects:
719
719
// The outer can be a bottom value for top-level classes.
720
720
721
721
if klass == defn.ArrayClass then
722
- OfArray (State .currentObject)
722
+ val arr = OfArray (State .currentObject)
723
+ Heap .write(arr.addr, Bottom )
724
+ arr
723
725
else
724
726
// Widen the outer to finitize the domain. Arguments already widened in `evalArgs`.
725
727
val (outerWidened, envWidened) =
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments