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 
> <[email protected]> wrote:
> 
> 
> 
> 
> On April 11, 2017 at 11:38:05 AM, Joe Groff ([email protected] 
> <mailto:[email protected]>) 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
> [email protected] <mailto:[email protected]>
> https://lists.swift.org/mailman/listinfo/swift-evolution 
> <https://lists.swift.org/mailman/listinfo/swift-evolution>
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to