Skip to content

Conversation

@ahoppen
Copy link
Member

@ahoppen ahoppen commented Jun 16, 2023

See swiftlang/swift-syntax#1802

Allow keywords after `#` in freestanding macro expansions

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#66444
rdar://110472060
@ahoppen ahoppen requested a review from a team as a code owner June 16, 2023 13:16
@ahoppen
Copy link
Member Author

ahoppen commented Jun 19, 2023

swiftlang/swift-syntax#1802

@swift-ci Please test

@ahoppen ahoppen merged commit 1b9cc10 into swiftlang:release/5.9 Jun 20, 2023
@ahoppen ahoppen deleted the ahoppen/5.9/keyword-freestanding-macro-names branch June 20, 2023 09:25
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