I have the following struct:
struct Pair<First, Second> {
var first: First
var second: Second
static func ~= (pattern: (First, Second), value: Pair) -> Bool { /* code */ }
}
Now, the test code:
func test() {
let tuple = (0, "zero")
let pair = Pair(0, "zero")
(0, "zero") ~= pair
tuple ~= pair
switch pair {
case tuple: return
case (0, "zero"): return // only this raises an error
// error: tuple pattern cannot match values of the non-tuple type 'Pair<Int, String>'
default: return
}
}
Question: It doesn't seem like it's an issue with matching a tuple literal vs. a tuple instance, since a non-switch version is working fine.
I'm wondering if this is some bug, or there is something I need to know about switch statements.