swift
swift copied to clipboard
Keywords like `case` cannot be used, unescaped, as expression macro names
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
extension Int {
static let `case` = 1
}
let _: Int = .case // β
@freestanding(expression)
public macro `case`(Int) -> Int = β¦
let _ = #case(42) // π
let _ = #`case`(42) // β
Expected behavior
I expect #case(42) to compile OK.
Environment
- Swift compiler version info
swift-driver version: 1.82.2 Apple Swift version 5.9 (swiftlang-5.9.0.114.6 clang-1500.0.27.1) Target: arm64-apple-macosx13.0 - Xcode version info
Xcode 15.0 Build version 15A5160n
cc @ahoppen
In case this also applies to the new parser.
The new parser has the same issue
swift-parser-cli print-diags -s '#case'
=== stdin:1 ===
1 β #case
β β°β error: keyword 'case' cannot be used as an identifier here
Tracked in Appleβs issue tracker as rdar://110472060.