Created
August 17, 2015 19:34
-
-
Save NachoSoto/19499b0a52513c1671c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compile with `swiftc switch.swift` | |
enum A { | |
case A(Int) | |
case B(Bool) | |
case C | |
case D | |
} | |
enum B { | |
case A | |
case B | |
} | |
func s(a: A, b: B) { | |
// error: switch must be exhaustive, consider adding a default clause | |
// WTF | |
switch (a, b) { | |
case let (.A(i), .A): | |
break | |
case let (.A(i), .B): | |
break | |
case let (.B(boolean), b): | |
break | |
case (.C, _), (.D, _): | |
break | |
} | |
} |
Looks like it can’t infer b
’s cases when a
is either .C
or .D
, only this works:
func s(a: A, b: B) {
switch (a, b) {
case let (.A(i), .A):
print(i)
break
case let (.A(i), .B):
print(i)
break
case let (.B(boolean), .A):
print(boolean)
break
case let (.B(boolean), .B):
print(boolean)
break
case (.C, B.A):
break
case (.C, B.B):
break
case (.D, B.A):
break
case (.D, B.B):
break
}
}
Note: this was done in Swift 2.0 beta 5.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the second
b
isn't supposed to be.B
?Also aren't you missing
.B(boolean), .A
?