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

Robert Widmann devteam.codafi at gmail.com
Tue Apr 11 18:00:42 CDT 2017


What Joe is referring to is the kind of refinement-style rules that would be necessary to teach the type checker about how to that kind of analysis.  Right now, all our switch analysis, and even this example, are just DI and control-flow checks.

> On Apr 11, 2017, at 2:24 PM, Drew Crawford via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
> 
> 
> On April 11, 2017 at 11:38:05 AM, Joe Groff (jgroff at apple.com <mailto: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
> 
> }
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170411/3ed7687b/attachment.html>


More information about the swift-evolution mailing list