-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Keywords like case
cannot be used, unescaped, as expression macro names
#66444
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
Labels
backticked identifiers
Feature → identifiers: Backticked identifiers. Allows using reserved words as identifiers
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler itself
expressions
Feature: expressions
identifiers
Feature: Identifiers
macro expansions
Feature → expressions: Macro expansion expressions
parser
Area → compiler: The legacy C++ parser
swift 5.9
unexpected error
Bug: Unexpected error
Comments
cc @ahoppen In case this also applies to the new parser. |
The new parser has the same issue
|
Tracked in Apple’s issue tracker as rdar://110472060. |
ahoppen
added a commit
to ahoppen/swift-syntax
that referenced
this issue
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
ahoppen
added a commit
to ahoppen/swift-syntax
that referenced
this issue
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
ahoppen
added a commit
to ahoppen/swift-syntax
that referenced
this issue
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
ahoppen
added a commit
to ahoppen/swift
that referenced
this issue
Jun 14, 2023
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
added a commit
to ahoppen/swift
that referenced
this issue
Jun 14, 2023
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
added a commit
to ahoppen/swift
that referenced
this issue
Jun 15, 2023
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
added a commit
to ahoppen/swift-syntax
that referenced
this issue
Jun 16, 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
ahoppen
added a commit
to ahoppen/swift
that referenced
this issue
Jun 16, 2023
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
backticked identifiers
Feature → identifiers: Backticked identifiers. Allows using reserved words as identifiers
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler itself
expressions
Feature: expressions
identifiers
Feature: Identifiers
macro expansions
Feature → expressions: Macro expansion expressions
parser
Area → compiler: The legacy C++ parser
swift 5.9
unexpected error
Bug: Unexpected error
Description
I was hoping keywords like
case
could be used as expression macro names in an unescaped manner, like static functions and methods, but sadly that doesn't seem to be the case.Steps to reproduce
Expected behavior
I expect
#case(42)
to compile OK.Environment
The text was updated successfully, but these errors were encountered: