Skip to content

[5.9] [Macros] Fix lookup of macro-produced variables #66010

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 1 commit into from
May 19, 2023

Conversation

rxwei
Copy link
Contributor

@rxwei rxwei commented May 18, 2023

Cherry-pick #65939 into release/5.9


  • Explanation: Macro-produced variables could not be found because the way we retrieved the parent source file from a macro-produced decl did not work on PatternBindingDecls. The fix is to switch to using getSourceFileContainingLocation as a more reliable approach.
  • Scope: This touches the lazy macro expansion logic (MissingDecl) and the logic adding members to an IterableDeclContext.
  • Risk: Low. Source-location-based source file retrieval is more reliable, but we fall back to the old approach upon invalid source locations.
  • Testing: Added test cases, and updated an existing test that has been fixed.
  • Issue: rdar://109376568
  • Reviewers: @DougGregor

Calling `getInnermostDeclContext()->getParentSourceFile()` on a macro-produced decl does not seem to be a reliable way to obtain the macro expansion source file, because `PatternBindingDecl` is not a `DeclContext` and `getInnermostDeclContext()` falls back outside the macro expansion file. This patch switches to using `getSourceFileContainingLocation` when possible.

Resolves rdar://109376568.
@rxwei rxwei requested a review from a team as a code owner May 18, 2023 23:14
@rxwei
Copy link
Contributor Author

rxwei commented May 18, 2023

@swift-ci please test

@rxwei rxwei changed the title [Macros] Fix lookup of macro-produced variables (#65939) [5.9] [Macros] Fix lookup of macro-produced variables May 18, 2023
@rxwei rxwei merged commit 648d15e into swiftlang:release/5.9 May 19, 2023
@rxwei rxwei deleted the rdar109376568-59 branch May 19, 2023 04:30
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.

2 participants