Skip to content

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

No newline at end of file
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.

Env.resolveEnv(klass.owner.enclosingMethod, thisV, summon[Env.Data]).getOrElse(Cold -> Env.NoEnv)

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