Skip to content

Allow keywords after # in freestanding macro expansions #1778

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

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jun 14, 2023

There is no reason why we shouldn’t allow keywords here.

I also thought about allowing keywords after @ but things become tricky here for two reasons:

  • In the parser, we parse a type after the @, which could start with a keyword itself (e.g. any). If we want to keep the parser logic to parse a type after @ (which I think we should), then it becomes unclear what @any T should parse as.
  • We allow a space between @ and the type name. This makes it very hard for recovery to tell whether @ struct refers to an attribute with name struct or if the user forgot to write the attribute name after @.

Since almost all keywords are lowercase and attached member macros are usually spelled with an uppercase name, there are a lot fewer chances for clashes here, so I don’t think it’s worth allowing keywords after @.

swiftlang/swift#66444
rdar://110472060

I will work on a corresponding compiler PR tomorrow.

There is no reason why we shouldn’t allow keywords here.

I also thought about allowing keywords after `@` but things become tricky here for two reasons:
- In the parser, we parse a type after the `@`, which could start with a keyword itself (e.g. `any`). If we want to keep the parser logic to parse a type after `@` (which I think we should), then it becomes unclear what `@any T` should parse as.
- We allow a space between `@` and the type name. This makes it very hard for recovery to tell whether `@ struct` refers to an attribute with name `struct` or if the user forgot to write the attribute name after `@`.

Since almost all keywords are lowercase and attached member macros are usually spelled with an uppercase name, there are a lot fewer chances for clashes here, so I don’t think it’s worth allowing keywords after `@`.

swiftlang/swift#66444
rdar://110472060
@ahoppen ahoppen force-pushed the ahoppen/keyword-freestanding-macro-names branch from e54d492 to b7b047f Compare June 14, 2023 00:11
@ahoppen
Copy link
Member Author

ahoppen commented Jun 14, 2023

@swift-ci Please test

@ahoppen ahoppen merged commit 7834f2c into swiftlang:main Jun 16, 2023
@ahoppen ahoppen deleted the ahoppen/keyword-freestanding-macro-names branch June 16, 2023 13:02
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.

3 participants