Skip to content

[5.9] [ASTScope] Adjust parent location for peer macro to after its attached decl #64893

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

Conversation

DougGregor
Copy link
Member

  • Explanation: Unqualified name lookup within peer macro expansions were looking into the scope of the attached declaration. In the reported case, it meant that Self from the protocol to which the macro was attached was visible in types produced by the macro expansion (!).
  • Scope: Affects code using peer macro expansions.
  • Risk: Very low; only affects peer macro expansions.
  • Issue: rdar://107228586
  • Testing: Additional tests added.
  • Original pull request: [ASTScope] Adjust parent location for peer macro to after its attached decl. #64892

…d decl.

Peer macro produce declarations that are semantically alongside the
declaration to which the macro is attached. However, the source
location used for constructing the scope tree was based on the
attribute itself, which meant it was inside the scope of the
declaration to which the macro was attached. This lead to incorrect
unqualified name lookup; in the example that's now a test case, this
meant that the `Self` of the protocol to which the macro was attached
was visible from within the peer declaration. Hilarity (in the form of
a type checker crash) ensued.

Fix the location used for constructing the scope tree of peer macros to
be right after the attached declaration. Fixes rdar://107228586.
@DougGregor DougGregor requested a review from a team as a code owner April 4, 2023 04:44
@DougGregor
Copy link
Member Author

@swift-ci please test

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor merged commit e76c309 into swiftlang:release/5.9 Apr 5, 2023
@DougGregor DougGregor deleted the peer-macro-scope-tree-fix-5.9 branch April 5, 2023 00:16
@AnthonyLatsis AnthonyLatsis added the 🍒 release cherry pick Flag: Release branch cherry picks label May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants