Just saw this thread after posting my question...
The @unknown default spelling looks non ideal, I'd rather prefer a bare syntax default behaving this exact way (as @8675309 pitching here)... but I guess that would be impossible without breaking compatibility:
switch someInt {
case 0: break
default: break // ok
}
// there's enum E { case a, b, c } somewhere
switch e {
case .a: break
default: break // Error or warning (as if @unknown default was written here)
}
switch e {
case .a, .b, .c: break
// error or warning because it's not frozen
}
switch e {
case .a, .b, .c: break
default: break // ok (as if @unknown default was written here)
}
I wonder though how well this (or the pitched approach) solves the general issue.. I could write default without mentioning it:
// there's enum E { case a, b, c } somewhere
switch e {
case .a: break
case _: break
}
The simple linter would probably allow it because it doesn't see default but it effectively is there.. Or something more elaborate:
// there's enum E { case a } somewhere
// there's enum F { case c, d } somewhere
switch (e, f) {
case (.a, .c): break
case (.a, _): break
}
Maybe this is a deeper feature, and not necessarily appropriate for linters (simple or complex) but could/should be embedded in the compiler itself?
There's another angle, maybe we'd also need to prohibit (discourage via a warning) having the else here at all (or even using == for enum types):
if v == .a { // like `case .a`
} else if v == .b { // like `case .b`
} else { // like `default`, but no warning?
}