<div dir="ltr">I have a suggestion.<div>Suppose we think of 'switch' as being like a non-optional type. The compiler does its thing and tries to ensure that the switched expression will match something, and enforces a default if it cannot verify a matching state.</div><div>Could we force the switch? i.e. suffix the 'switch' keyword with an exclamation mark, to say: the programmer insists that one of these cases will match; there's no need for a default case, but if nothing matches then crash.</div><div><br></div><div>For example:</div><div><span style="font-size:13px">let x:Int</span></div><div>switch! expression</div><div>{</div><div> case ... { x = 1 }</div><div> case ... { x = 2 }</div><div> // no default. the ! signifies that the app should crash if none of these cases matches the expression</div><div>}<br><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 12, 2016 at 5:32 PM, Chris Lattner via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Feb 12, 2016, at 9:27 AM, Amir Michail <<a href="mailto:a.michail@me.com">a.michail@me.com</a>> wrote:<br>
>>><br>
>>> What’s wrong with having the compiler explicitly check for “false”?<br>
>><br>
>> Weird special cases make the compiler less predictable.<br>
><br>
</span>> True, but not having them requires deeper knowledge of the standard libraries.<br>
><br>
> In practice, just checking for “false” would solve this problem.<br>
<br>
That is not what you’re actually proposing. You are proposing that the compiler encode special knowledge of the precondition *library function* into the compiler, and teach it about a single special case. We don’t like the compiler to have special cases like this for a large number of reasons, in particular, if we did this, someone would file a bug asking for *their* equivalent reimplementation of precondition to have the same magic blessed behavior.<br>
<br>
This is a slippery slope that leads to a lot of complexity downstream, it is better to keep the compiler simple and predictable. Also, as other people have pointed out, this has already been solved for you: just use preconditionFailure.<br>
<div class="HOEnZb"><div class="h5"><br>
-Chris<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</div></div></blockquote></div><br></div>