Design Priorities for the Swift 6 Language Mode

One more source-breaking change that I'd like to mention in case I forget: if you switch over a non-frozen enum and forget to include a catch-all clause, that is currently only a warning (and a trap at runtime if it ever encounters an added case) rather than a compiler error:

Example:

func test(_ x: FloatingPointRoundingRule) {
    switch x {
    // ^ warning: switch covers known cases, but 'FloatingPointRoundingRule' may have additional unknown values, possibly added in future versions
    // ^ note: handle unknown values using "@unknown default"
    case .up,
         .down,
         .toNearestOrEven,
         .toNearestOrAwayFromZero,
         .towardZero,
         .awayFromZero:
      print("foo")
    }
}

Godbolt

It seems the original goal of SE-0192 - Handling Future Enum Cases was for this to be an error, but the rollout was considered too aggressive for Swift 5.0, so it was softened to a warning + runtime trap:

Honestly, I hope enough time has passed that we can make this change in a Swift 5.x update, but if not, let's please finally do it in Swift 6.

CC @jrose

24 Likes