> On Apr 8, 2017, at 11:29 AM, Drew Crawford via swift-evolution > <[email protected]> wrote: > > > > 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 > >
By design, Swift avoids making semantic rules based on that kind of analysis, since it would be brittle and difficult to describe when the compiler can and can't see that a condition holds nonlocally like this. -Joe
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
