[swift-evolution] switch must be exhaustive, consider adding a default clause
Drew Crawford
drew at drewcrawfordapps.com
Tue Apr 11 13:24:20 CDT 2017
On April 11, 2017 at 11:38:05 AM, Joe Groff (jgroff at apple.com) wrote:
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.
Swift *currently implements* semantic rules based on this kind of analysis. Exhibit A:
func foo() {
let a: Bool
if UUID().uuidString == "non-local condition" {
a = true
}
else {
preconditionFailure("Don't initialize a")
}
print("\(a)") //NOT: error: a is uninitialized
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170411/18968c3c/attachment.html>
More information about the swift-evolution
mailing list