<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 11, 2017, at 11:24 AM, Drew Crawford &lt;<a href="mailto:drew@drewcrawfordapps.com" class="">drew@drewcrawfordapps.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><br style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div id="bloop_sign_1491934987204692992" class="bloop_sign" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"></div><br style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><p class="airmail_on" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On April 11, 2017 at 11:38:05 AM, Joe Groff (<a href="mailto:jgroff@apple.com" class="">jgroff@apple.com</a>) wrote:</p><div style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class="clean_bq" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class=""><div class=""><span style="font-family: 'helvetica Neue', helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); float: none; display: inline !important;" class="">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.</span></div></span></blockquote></div><p style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Swift *currently implements* semantic rules based on this kind of analysis. &nbsp;Exhibit A:</p><blockquote style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><p class="">func foo() {</p><p class="">&nbsp; &nbsp; let a: Bool</p><p class="">&nbsp; &nbsp; if UUID().uuidString == "non-local condition" {</p><p class="">&nbsp; &nbsp; &nbsp; &nbsp; a = true</p><p class="">&nbsp; &nbsp; }</p><p class="">&nbsp; &nbsp; else {</p><p class="">&nbsp; &nbsp; &nbsp; &nbsp; preconditionFailure("Don't initialize a")</p><p class="">&nbsp; &nbsp; }</p><p class="">&nbsp; &nbsp; print("\(a)") //NOT: error: a is uninitialized</p><p class="">}</p></blockquote></div></blockquote></div>That analysis is pretty strictly limited as well. The DI assignment has to happen once along every code path before the variable is ever read or escaped, so the effects are localized. To do pattern matching refinement something like you're proposing, we need to know that the value isn't mutated between switches. That becomes impossible if the variable is ever escaped, so you'd get spooky action at a distance where referencing the variable in a closure somewhere would cause seemingly-unrelated control flow errors to spring up seeming randomly; global variables and class properties would also fundamentally never benefit from this analysis, making it feel inconsistent when exactly the refined switch is allowed.<div class=""><br class=""></div><div class="">-Joe</div></body></html>