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 references to class members defined in quotes #17107

Merged
merged 1 commit into from
Mar 21, 2023

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Mar 15, 2023

If an inner quote selects a symbol that is defined in an outer quote we need to transform it or reject it. The issue is that the inner quote cannot contain a reference to the type of the class defined in the outer quote. Any such reference is erased the parents of that class that are statically know outside those quotes. If the selected symbol is overriding a symbol in one of those statically known classes, we can use that overridden symbol instead. If not we have to reject the code.

Fixes #17103

If an inner quote selects a symbol that is defined in an outer quote we
need to transform it or reject it. The issue is that the inner quote
cannot contain a reference to the type of the class defined in the outer
quote. Any such reference is erased the parents of that class that are
statically know outside those quotes. If the selected symbol is
overriding a symbol in one of those statically known classes, we can use
that overridden symbol instead. If not we have to reject the code.

Fixes scala#17103
@@ -208,6 +208,14 @@ class Splicing extends MacroTransform:

override def transform(tree: tpd.Tree)(using Context): tpd.Tree =
tree match
case tree: Select if tree.isTerm && isCaptured(tree.symbol) =>
tree.symbol.allOverriddenSymbols.find(sym => !isCaptured(sym.owner)) match
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it matter if there are multiple overridden symbols that are not captured? I think it doesn't but just want to make sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should no matter.

@nicolasstucki nicolasstucki merged commit d36cd2d into scala:main Mar 21, 2023
@nicolasstucki nicolasstucki deleted the fix-17103 branch March 21, 2023 13:25
@Kordyjan Kordyjan added this to the 3.3.1 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.

Reference to quoted local member fails to in quote pickling
3 participants