Skip to content

Fix #15883: Interpret inner static object access as this access #15984

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

Merged
merged 5 commits into from
Sep 10, 2022

Conversation

liufengyun
Copy link
Contributor

Fix #15883: Interpret inner static object access as this access

@liufengyun liufengyun marked this pull request as ready for review September 7, 2022 07:34
@liufengyun liufengyun requested a review from olhotak September 7, 2022 07:34
@olhotak
Copy link
Contributor

olhotak commented Sep 7, 2022

I can't figure out how this works. I mean before this PR, the initialization checker does not process top-level vals at all. Where in the patch does it add top-level code to the code that the initialization checker processes? I can't find it.

@liufengyun
Copy link
Contributor Author

liufengyun commented Sep 8, 2022

I can't figure out how this works. I mean before this PR, the initialization checker does not process top-level vals at all. Where in the patch does it add top-level code to the code that the initialization checker processes? I can't find it.

The top-level vals will be inside a synthesized top-level wrapper object, thus it's transparent to the init checker.

The problem with the bug is how we interpret O.f. By default, the checker returns Hot for top-level object O, and selecting a field on it will also give Hot. That's the reason why we miss the warning for the issue.

Now, we change the logic, in interpreting a static object O:

  • If O is accessed inside the class O$, it's interpreted as O.this
  • If O is inside the entry class, it goes through this selection from the entry class.

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

@liufengyun liufengyun merged commit 282b68b into scala:main Sep 10, 2022
@liufengyun liufengyun deleted the fix-15883 branch September 10, 2022 16:12
@Kordyjan Kordyjan added this to the 3.2.2 milestone Aug 1, 2023
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.

No "Reference to uninitialized value" warning
3 participants