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

Conversation

EnzeXing
Copy link
Contributor

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.

@EnzeXing EnzeXing changed the title Fix uninitializing fields when evaluating a cached constructor call Fix uninitializing fields when evaluating a cached constructor call in global initialization checker Aug 20, 2024
Copy link
Contributor

@liufengyun liufengyun left a 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

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.

@@ -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

Copy link
Contributor

@olhotak olhotak left a 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.

@olhotak olhotak enabled auto-merge August 20, 2024 18:28
@olhotak olhotak merged commit 04ebb28 into scala:main Aug 20, 2024
26 checks passed
WojciechMazur added a commit that referenced this pull request Aug 28, 2024
…tor call in global initialization checker" to 3.5.2 (#21494)

Backports #21403 to the 3.5.2 branch.

PR submitted by the release tooling.
[skip ci]
@WojciechMazur WojciechMazur added this to the 3.5.2 milestone Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants