[swift-evolution] switch must be exhaustive, consider adding a default clause

Drew Crawford drew at drewcrawfordapps.com
Sat Apr 8 13:29:21 CDT 2017



Is there a good reason we do not compile this:

import UIKit

func foo(operation: UINavigationControllerOperation) {
    switch(operation) {
    case .push: /* snip */ break
    case .pop: /* snip */ break
    default:
        preconditionFailure("This is a silly operation")
    }
    switch(operation) {
        case .push: /* snip */ break
        case .pop: /* snip */ break
         //error: Switch must be exhaustive, consider adding a default clause
    }
}
The switch *is* exhaustive, because the default case is unreachable.  The compiler could infer as much from branch analysis.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170408/4dd75dbf/attachment.html>


More information about the swift-evolution mailing list