Skip to content

Commit a722358

Browse files
author
EnzeXing
committed
Fix uninitializing fields when evaluating a cached constructor call
1 parent f1adc55 commit a722358

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/transform/init/Objects.scala

-1
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,6 @@ class Objects(using Context @constructorOnly):
950950

951951
val instance = OfClass(klass, outerWidened, ctor, args.map(_.value), envWidened)
952952
callConstructor(instance, ctor, args)
953-
instance
954953

955954
case ValueSet(values) =>
956955
values.map(ref => instantiate(ref, klass, ctor, args)).join

Diff for: tests/init-global/pos/cache-constructor.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Bar:
2+
var f: Int = 0
3+
4+
object A:
5+
val b1 = new Bar()
6+
val b2 = new Bar()
7+
val b3 = new Bar()
8+
b3.f = 1
9+

0 commit comments

Comments
 (0)