-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
compilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of Implementationgood first issueGood for newcomersGood for newcomersimprovementparserArea → compiler: The legacy C++ parserArea → compiler: The legacy C++ parserpatternsFeature: patternsFeature: patternsstatementsFeature: statementsFeature: statementsswift 6.1
Description
| Previous ID | SR-2022 |
| Radar | None |
| Original Reporter | @karwa |
| Type | Improvement |
| Status | In Progress |
| Resolution |
Additional Detail from JIRA
| Votes | 0 |
| Component/s | Compiler |
| Labels | Improvement, DiagnosticsQoI, Parser, StarterBug |
| Assignee | None |
| Priority | Medium |
md5: 9b53adc1e41e34c46ad044ffe4bfbac9
Issue Description:
switch myVariable {
case let intValue as? Int: print("Hello, I'm an int: \(intValue)")
case let stringValue as? String: print("Hello, I'm a string: \(stringValue)")
default: print("Some other value...")
}Gives you an error on the casting lines saying "Invalid pattern". It would be better if it told you to make the casts non-conditional, I.e.:
switch myVariable {
case let intValue *as Int*: print("Hello, I'm an int: \(intValue)")
case let stringValue *as String*: print("Hello, I'm a string: \(stringValue)")
default: print("Some other value...")
}Metadata
Metadata
Assignees
Labels
compilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of Implementationgood first issueGood for newcomersGood for newcomersimprovementparserArea → compiler: The legacy C++ parserArea → compiler: The legacy C++ parserpatternsFeature: patternsFeature: patternsstatementsFeature: statementsFeature: statementsswift 6.1