Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a comment above callConstructor and refer to the test. Something like the following:

// The actual instance might be cached without running the constructor. 
// See tests/init-global/pos/cache-constructor.scala

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: trailing spaces in file.