Skip to content

[Macros] Add missing macro validation. #67106

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 2 commits into from
Jul 14, 2023

Conversation

hborla
Copy link
Member

@hborla hborla commented Jul 4, 2023

  • Extension macros must document extension member names in the @attached(extension) attribute. Otherwise, the compiler emits an error that the generated name is not covered.
  • Emit an error when an attached macro cannot apply to the declaration it's attached to, such as a member macro attached to an import declaration.

Resolves rdar://111685434

@hborla hborla requested review from slavapestov and xedin as code owners July 4, 2023 06:23
@hborla hborla changed the title [Macros] Validate that extension macro expansions only include names covered by the macro declaration. [Macros] Add missing macro validation. Jul 13, 2023
@hborla hborla force-pushed the validate-extension-macros branch from fa11530 to 1756ee7 Compare July 13, 2023 23:32
@hborla
Copy link
Member Author

hborla commented Jul 13, 2023

@swift-ci please smoke test

@hborla hborla force-pushed the validate-extension-macros branch from 1756ee7 to 04ea8b0 Compare July 14, 2023 00:07
@hborla
Copy link
Member Author

hborla commented Jul 14, 2023

@swift-ci please smoke test

case MacroRole::Conformance:
case MacroRole::Extension:
// Only primary declarations of nominal types
if (isa<NominalTypeDecl>(attachedTo))
Copy link
Member

Choose a reason for hiding this comment

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

I thought one would be allowed to put an extension macro on an extension?

Copy link
Member Author

Choose a reason for hiding this comment

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

The only reason I banned extensions here is because I didn't implement it yet. This came up in the review thread too. It should be very straightforward to generalize the places that assume an extension macro is applied to a NominalTypeDecl.

@hborla hborla merged commit c55d0e2 into swiftlang:main Jul 14, 2023
@hborla hborla deleted the validate-extension-macros branch July 14, 2023 14:53
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