Skip to content

Commit

Permalink
Fix uninitializing fields when evaluating a cached constructor call
Browse files Browse the repository at this point in the history
  • Loading branch information
EnzeXing committed Aug 20, 2024
1 parent f1adc55 commit a722358
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/init/Objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,6 @@ class Objects(using Context @constructorOnly):

val instance = OfClass(klass, outerWidened, ctor, args.map(_.value), envWidened)
callConstructor(instance, ctor, args)
instance

case ValueSet(values) =>
values.map(ref => instantiate(ref, klass, ctor, args)).join
Expand Down
9 changes: 9 additions & 0 deletions tests/init-global/pos/cache-constructor.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Bar:
var f: Int = 0

object A:
val b1 = new Bar()
val b2 = new Bar()
val b3 = new Bar()
b3.f = 1

0 comments on commit a722358

Please sign in to comment.