<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="">I think I agree with you. The postfix `!` operator is always shorthand for `fatalError()` (and some more syntax), and it would fit nicely with `default: fatalError()`.<div class=""><br class=""></div><div class="">The Swift usage of `?` is indeed different than `default: break` would do, so `switch?` wouldn’t convey the right message. I hadn’t given it enough thought. I still think a shorthand for `default: break` would be _nice_, but it surely shouldn’t change the `?` consistency, it also shouldn’t replace the current `switch` (as exhaustiveness is very useful) and it’s probably not worth introducing new syntax for.</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 4 Oct 2016, at 16:36, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">There is a plausible argument for `switch!`, because it is not possible for the compiler to prove exhaustiveness in all circumstances where you might know it to be the case.<br class=""><br class="">However, I'd be very against `switch?`: it undermines the exhaustiveness guarantee of the switch statement and is wholly inconsistent with Swift usage of `?`, which indicates the possibility of an Optional. We simply don't need a new spelling for `default: break`.<br class=""><div class="gmail_quote"><div dir="ltr" class="">On Tue, Oct 4, 2016 at 3:35 AM Tim Vermeulen via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I agree about exhaustiveness checks being very useful. There was a suggestion for `switch?` implicitly adding `default: break`, `switch!` implicitly adding `default: fatalError()`, and `switch` remaining as it is now. I think that’s a great compromise, would you be in favor of that?<br class="gmail_msg">
<br class="gmail_msg">
> -1. The “default: break” is not only not difficult to write, it clearly communicates the programmer’s intent to only handle a subset of the cases. Without it, it is impossible to know whether that was intended, or by accident. Furthermore, the exhaustiveness by default can catch many mistakes, including after an additional case is added to an enum.<br class="gmail_msg">
><br class="gmail_msg">
> Charles<br class="gmail_msg">
><br class="gmail_msg">
> > On Oct 3, 2016, at 5:14 AM, Adrian Zubarev via swift-evolution<swift-evolution at <a href="http://swift.org/" rel="noreferrer" class="gmail_msg" target="_blank">swift.org</a>>wrote:<br class="gmail_msg">
> ><br class="gmail_msg">
> > I know that there is this note in Commonly Rejected Changes<<a href="https://github.com/apple/swift-evolution/blob/master/commonly_proposed.md" rel="noreferrer" class="gmail_msg" target="_blank">https://github.com/apple/swift-evolution/blob/master/commonly_proposed.md</a>>:<br class="gmail_msg">
> ><br class="gmail_msg">
> > Remove support for default: in switch and just use case _:: default is widely used, case _ is too magical, and default is widely precedented in many C family languages.<br class="gmail_msg">
> > I really like to use the switch instead of if case for pattern matching, just because it’s neat block design. I do not want to remove default from switches because it’s a must have and powerful feature.<br class="gmail_msg">
> ><br class="gmail_msg">
> > I’d like to know why switches must be exhaustive.<br class="gmail_msg">
> ><br class="gmail_msg">
> > switch someValue {<br class="gmail_msg">
> ><br class="gmail_msg">
> > case …:<br class="gmail_msg">
> > // Do something<br class="gmail_msg">
> ><br class="gmail_msg">
> > case …:<br class="gmail_msg">
> > // Do something else<br class="gmail_msg">
> ><br class="gmail_msg">
> > default:<br class="gmail_msg">
> > () // useless nop; do nothing when no pattern matched<br class="gmail_msg">
> > }<br class="gmail_msg">
> ><br class="gmail_msg">
> > // VS:<br class="gmail_msg">
> ><br class="gmail_msg">
> > if case … {<br class="gmail_msg">
> ><br class="gmail_msg">
> > } else if case … {<br class="gmail_msg">
> ><br class="gmail_msg">
> > } else if case … {<br class="gmail_msg">
> ><br class="gmail_msg">
> > } // No need for `else`<br class="gmail_msg">
> > Can’t we make default optional, or at least on non-enum values?<br class="gmail_msg">
> ><br class="gmail_msg">
> ><br class="gmail_msg">
> ><br class="gmail_msg">
> ><br class="gmail_msg">
> > --<br class="gmail_msg">
> > Adrian Zubarev<br class="gmail_msg">
> > Sent with Airmail<br class="gmail_msg">
> ><br class="gmail_msg">
> > _______________________________________________<br class="gmail_msg">
> > swift-evolution mailing list<br class="gmail_msg">
> > swift-evolution at <a href="http://swift.org/" rel="noreferrer" class="gmail_msg" target="_blank">swift.org</a><mailto:<a href="mailto:swift-evolution" class="gmail_msg" target="_blank">swift-evolution</a> at <a href="http://swift.org/" rel="noreferrer" class="gmail_msg" target="_blank">swift.org</a>><br class="gmail_msg">
> > <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a>><br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
><br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>
</div></blockquote></div><br class=""></div></body></html>