<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></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 Feb 12, 2016, at 11:27 AM, Ross O'Brien &lt;<a href="mailto:narrativium+swift@gmail.com" class="">narrativium+swift@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">It would be really helpful if you could describe the problem you're experiencing so I don't have to guess what it is from your example code.</div><div class=""><br class=""></div></div></div></blockquote><div><br class=""></div><div>I want to ensure that one of the cases applies. Otherwise, there is a bug in my code. That’s why I have the precondition(false).</div><div><br class=""></div><div>However, writing code like this is annoying:</div><div><br class=""></div><div>let x:Int<br class="">if … { x = 1 }<br class="">else if … { x = 2 }<br class="">else { x = dummyValue; precondition(false) }&nbsp;</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">Am I guessing right if I say that you want a change to Swift such that a switch initialisation can be 'force-unwrapped', such that if none of the cases apply, the app crashes, in a more explicit fashion?</div><div class=""><br class=""></div><div class="">I've written code like this, but I've tended towards 'default: fatalError()', which wouldn't be covered by your suggestion. 'precondition' isn't at fault here.</div><div class=""><br class=""></div><div class="">Just as a digression, I've just learned that 'precondition(false)' doesn't cause any immediately following code to receive the compiler warning 'will never be executed' that code in a 'if false { ... }' does. So that would be nice.<br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, Feb 12, 2016 at 3:59 PM, Amir Michail via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">For example:<br class="">
<br class="">
let x:Int<br class="">
if … { x = 1 }<br class="">
else if … { x = 2 }<br class="">
else { precondition(false) } // no initialization needed<br class="">
<br class="">
Similarly,<br class="">
<br class="">
let x:Int<br class="">
switch ... {<br class="">
case …: x = 1<br class="">
case …: x = 2<br class="">
default: precondition(false) // no initialization needed<br class="">
}<br class="">
_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>