-
Couldn't load subscription status.
- Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itself
Description
| Previous ID | SR-7799 |
| Radar | rdar://problem/41494702 |
| Original Reporter | @martinr448 |
| Type | Bug |
| Status | Closed |
| Resolution | Done |
Additional Detail from JIRA
| Votes | 0 |
| Component/s | Compiler |
| Labels | Bug |
| Assignee | @theblixguy |
| Priority | Medium |
md5: 866262f404c0af00426fbd898e2b0060
Issue Description:
We can match an optional Int against a non-optional value:
let x: Int? = 1
switch x {
case 1: print("one")
default: print("default")
}But the same does not compile with an optional enum:
enum MyEnum { case a, b }
let e: MyEnum? = .a
switch e {
case .a: print("a") // error: Enum case 'a' not found in type 'MyEnum?'
case .some(.a): print("some a") // OK
default: print("default")
}Tested with Xcode 9.3.1, with both the default toolchain and the Swift 4.2 snapshot from May 20, 2018.
Related discussion in the Swift forum: Matching optionals in a switch statement, where Joe Groff said:
It ought to compile as well. That's a bug.
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itself