Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix uninitializing fields when evaluating a cached constructor call in global initialization checker #21403

Merged
merged 2 commits into from
Aug 20, 2024
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.

Loading