-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @EnzeXing , this is a beautiful fix 🎉
val b2 = new Bar() | ||
val b3 = new Bar() | ||
b3.f = 1 | ||
|
There was a problem hiding this comment.
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.
@@ -950,7 +950,6 @@ class Objects(using Context @constructorOnly): | |||
|
|||
val instance = OfClass(klass, outerWidened, ctor, args.map(_.value), envWidened) | |||
callConstructor(instance, ctor, args) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, pending @liufengyun 's minor suggestions.
This PR fixes the accessing uninitialized field errors given by the global initialization checker, where fields are uninitialized when evaluating a cached constructor call during the analysis.