Avatar
Avatar
masakihori
The Swift Programming LanguageのSummary of the Grammarとswiftcの実装に齟齬があるのを見つけました Summary of the Grammar
pattern → optional-pattern optional-pattern → identifier-pattern ? identifier-pattern → identifier
? の前はidentifier-pattern(=identifier)のみ @swift-main let g = { 1..<10 } func f(_ i: Int?) -> String { switch i { case (..<0)?: "minus" // ?の前が tupple-pattern case 0?: "zero" // ?の前が expression-pattern case g()?: "1 to 9" // ?の前が expression-pattern case Int(10)?: "ten" // ?の前が expression-pattern case _?: "other" // ?の前が wildcard-pattern default: "nil" } } enum E { case a } let e: E? = .a switch e { case .a?: () // ?の前が enum-case-pattern default: () } だいたいなんでもコンパイルできる たぶんGrammarの方を
optional-pattern → pattern ?
にするべき?
(edited)
swiftNightly BOT 2/10/2025 8:42 AM
no output (edited)