<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=""><div class="">Ah, I get it now. Even if the switch knows what to do with the unknown value, the rest of your code would have to know what to do with it, and that is unlikely.</div><div class=""><br class=""></div><div class="">-Kenny</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Sep 18, 2017, at 10:23 AM, Jordan Rose &lt;<a href="mailto:jordan_rose@apple.com" class="">jordan_rose@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; 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=""><br class="Apple-interchange-newline"><br class=""><blockquote type="cite" class=""><div class="">On Sep 16, 2017, at 15:35, Kenny Leung via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">In general, I agree with everything in the proposal.</div><div class=""><br class=""></div><div class="">I’d like to propose these alternative extensions for clients:</div><div class=""><br class=""></div><div class="">1) As a client of an enum, I’d like to know in the future when a new value has been added to an enum, since I may have to do something about it. How about adding the “exhaustive” keyword to be used in the switch statement? Like</div><div class=""><br class=""></div><div class="">exhaustive switch excuse {<br class="">&nbsp; &nbsp; case&nbsp;eatenByPet:</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;…</div><div class="">&nbsp; &nbsp; case&nbsp;thoughtItWasDueNextWeek:<div class="">&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;…</div><div class="">&nbsp; &nbsp; default:</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; // …</div>}</div><div class=""><br class=""></div><div class="">If exhaustive is used, there would be a warning if all cases aren’t covered *even though default exists*. This means that I as the client thought I had everything covered when I wrote this code.</div><div class=""><br class=""></div><div class="">As already mentioned, this makes the default case un-testable, which brings me to</div><div class=""><br class=""></div><div class="">2) All non-exhaustive enums should have the pseudo value “default” that can be used just like a regular value. This would allow you to write code like:</div><div class=""><br class=""></div><div class="">teacher.failedToHandInHomework(excuse: .default)</div><div class=""><br class=""></div><div class="">which would allow you to trip the default case in any code you may write.</div></div></div></blockquote><br class=""></div><div style="font-family: Helvetica; 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="">Brent came up with this idea as well, but after thinking it through Joe Groff and I found that it doesn't really work in practice:</div><div style="font-family: Helvetica; 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=""><br class=""></div><div style="font-family: Helvetica; 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 class=""></div><blockquote type="cite" class=""><div class="">It’s going to be very common to have a future value and hand it right back to the framework without looking at it, for example:</div><div class=""><br class=""></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class="">override func process(_ transaction: @testable Transaction) {</div><div class="">&nbsp; switch transaction {</div><div class="">&nbsp; case .deposit(let amount):</div><div class="">&nbsp; &nbsp; // …</div><div class="">&nbsp; case .withdrawal(let amount):</div><div class="">&nbsp; &nbsp; // …</div><div class="">&nbsp; default:</div><div class="">&nbsp; &nbsp; super.process(transaction) // hmm…</div><div class="">&nbsp; }</div><div class="">}</div></blockquote><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space;"><div class=""><br class=""></div><div class="">So just making it to the ‘default’ case doesn’t guarantee that it’s testable in practice.</div></div></div></blockquote><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space;"><div class=""><br class=""></div></div></div></div><span style="font-family: Helvetica; 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; float: none; display: inline !important;" class="">I'll add the actual code here to the "Testing invalid cases" section under "Alternatives considered", since that's a clearer example than the paragraph I wrote. (Oh, and the "exhaustive switch" is equivalent to the section on "'future' cases".)</span><div class="" style="font-family: Helvetica; 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;"><br class=""></div><div class="" style="font-family: Helvetica; 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;">Thanks for the feedback!</div><div class="" style="font-family: Helvetica; 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;">Jordan</div></div></blockquote></div><br class=""></body></html>