They don't seem to be able to disambiguate, so, are they just for clarity in the situations where switch is actually functional? Is the lack of disambiguability with if just the same bug as switch, even though it compiles?
`Differently-named cases`: do {
enum E { case c(l: Void), notC }
#expect({
switch E.c(l: ()) {
case .c(l:): true
case .notC: false
}
}()) // ✅
#expect({
if case .c(l:) = E.c(l: ()) { true } else { false }
}()) // ✅
}
`Similarly-named cases`: do {
enum E { case c(l: Void), c(Never) }
#expect({
if case .c(l:) = E.c(l: ()) { true } else { false }
}()) // ❌
}
Testing more, I learned that labels can be used to get associated values out as tuples. Is this related?
enum E { case c(l: Int, Int) }
let e = E.c(l: 1, 2)
switch e {
case .c(`This label can be anything but _.`: let v):
#expect(v == (1, 2)) // ✅
}
#expect({
switch e {
case .c(l:_:): true
}
}()) // ✅