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

[5.10][Macros] Diagnose attached and freestanding declaration macros that produce something other than a declaration. #69106

Merged

Conversation

hborla
Copy link
Member

@hborla hborla commented Oct 10, 2023

  • Explanation: Attached and freestanding macros cannot expand to statements. However, the macro validation code was completely ignoring any ASTNode that isn't a declaration, allowing statement-producing macros to compile. Furthermore, for freestanding declaration macros, the experimental implementation of code item macros caused the invalid statements to be visited during SILGen, resulting in runtime crashes. This change diagnoses macro expansions that contain statements immediately after expansion.
  • Scope: Only impacts freestanding and attached macros that allow parsing ASTNodes that are not declarations.
  • Risk: Low.
  • Testing: Added a new regression test.
  • Reviewer: @DougGregor
  • Main branch PR: [Macros] Diagnose attached and freestanding declaration macros that produce something other than a declaration. #69089

…roduce

something other than a declaration.

The validation code already diagnosed all sorts of invalid declarations, but
it was ignoring AST nodes that aren't declarations at all.

(cherry picked from commit 1f07cba)
@hborla hborla requested a review from a team as a code owner October 10, 2023 22:49
@hborla
Copy link
Member Author

hborla commented Oct 10, 2023

@swift-ci please test

@hborla hborla merged commit 9c7df7a into swiftlang:release/5.10 Oct 11, 2023
5 checks passed
@hborla hborla deleted the 5.10-diagnose-invalid-declaration-macros branch October 11, 2023 14:01
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.

None yet

2 participants