SE-0192 — Non-Exhaustive Enums — review #2

In addition, it was previously noted that if case pattern matching doesn't make sense when used with unknown pattern, as 'there is no way to prevent it from producing a warning'.

But if you treat switch as a sequence of if-else statements, it becomes clear that:

  1. it doesn't make sense to use the unknown pattern in the first case of a switch statement as well;
  2. it makes perfect sense to use the unknown pattern after all known cases were considered in the sequence of if-else statements.
struct Example {
  func inspect(paperSize newValue: PaperSize) {
    if newValue == .usLetter || newValue == .a4 {
      print("usLetter or a4")

      // use normal pattern matching for the known enum case
    } else if case .photo4x6 = newValue {
      print("photo4x6")

      // use new pattern matching for the unknown enum case
      // no warning produced, because all known enum cases have been matched
    } else if case ._(let rawValue) = newValue {
      print("an unknown case with an associated value \(rawValue)")
    }
  }
}