swift icon indicating copy to clipboard operation
swift copied to clipboard

Keywords like `case` cannot be used, unescaped, as expression macro names

Open stephencelis opened this issue 2 years ago β€’ 3 comments

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
    

stephencelis avatar Jun 08 '23 02:06 stephencelis

cc @ahoppen

In case this also applies to the new parser.

AnthonyLatsis avatar Jun 08 '23 10:06 AnthonyLatsis

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

ahoppen avatar Jun 08 '23 17:06 ahoppen

Tracked in Apple’s issue tracker as rdar://110472060.

ahoppen avatar Jun 08 '23 17:06 ahoppen