Skip to content

[Macros] Disallow self and Self as macro names #64609

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
Mar 27, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Mar 24, 2023

We were allowing self and Self as freestanding macro names, which we don’t want.

Change parseDeclNameRef so that you need to explicitly request parsing of self or Self as the declaration’s base name, and adjust all call sites except those for macros to pass that flag.

We were allowing `self` and `Self` as freestanding macro names, which we don’t want.
@ahoppen
Copy link
Member Author

ahoppen commented Mar 24, 2023

@swift-ci Please smoke test

Comment on lines +3 to +4
@freestanding(expression) // expected-error {{expected expression}}
macro self() = #externalMacro(module: "MacroDefinition", type: "InvalidMacro")
Copy link
Member

Choose a reason for hiding this comment

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

This error message doesn't look right.

Copy link
Member Author

@ahoppen ahoppen Mar 24, 2023

Choose a reason for hiding this comment

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

I thought the same but I don’t think it’s worth improving it. This is silly code that I don’t expect anyone to write and if we think it’s worth improving the diagnostics for this, we should do so in the new parser.

The main motivation here is to make sure we don’t have to carry the baggage of supporting macros named self around later on.

@ahoppen ahoppen merged commit 5bb6f79 into swiftlang:main Mar 27, 2023
@ahoppen ahoppen deleted the ahoppen/no-self-macros branch March 27, 2023 18:23
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