Skip to content
New issue

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

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

Already on GitHub? # to your account

Avoid too eager transform of $outer for lhs & accessor rhs #18949

Merged
merged 1 commit into from
Nov 17, 2023

Conversation

szymon-rd
Copy link
Contributor

@szymon-rd szymon-rd commented Nov 16, 2023

Fix #18927

The transformer in mapOuter in Constructors was transforming trees it should not:

   override def transform(tree: Tree)(using Context) = tree match {
        [....]
        case tree: RefTree if tree.symbol.is(ParamAccessor) && tree.symbol.name == nme.OUTER =>
          ref(outerParam)
       [...]

There were two problems:

  • This case transformed LHS of $outer assignments in constructors. So, instead of setting the $outer field in the current class with the constructor, it was replaced with the $outer of the outer class. That resulted in not assigning any value to the $outer in inner class, and double assignment to the val in outer class.
  • LHS of the accessor def was also transformed, so it was evaluated to the $outer of the outer class.

This only happened when the nested class is created in the secondary constructor, as the primary constructor is not transformed (only the template body)

@szymon-rd szymon-rd changed the title Avoid too eager transform of for lhs & accessor rhs Avoid too eager transform of $outer for lhs & accessor rhs Nov 16, 2023
@szymon-rd szymon-rd force-pushed the fix-backend-crash-nested-classes branch from a8057d4 to 8c62ec9 Compare November 16, 2023 18:10
@szymon-rd szymon-rd force-pushed the fix-backend-crash-nested-classes branch from 8c62ec9 to 2ff4ba7 Compare November 16, 2023 18:23
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@odersky odersky merged commit 3b974c5 into main Nov 17, 2023
35 checks passed
@odersky odersky deleted the fix-backend-crash-nested-classes branch November 17, 2023 09:38
@Kordyjan Kordyjan added this to the 3.4.0 milestone Dec 20, 2023
WojciechMazur added a commit that referenced this pull request Jun 23, 2024
… to LTS (#20751)

Backports #18949 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash in backend in secondary constructor edge case
3 participants