<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 Jan 2, 2018, at 8:45 PM, Xiaodi Wu via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">On Tue, Jan 2, 2018 at 8:07 PM, Jordan Rose via swift-evolution <span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span> wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space" class=""><div class="">[Proposal: <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0192-non-exhaustive-enums.md" style="font-family:Helvetica,arial,sans-serif" target="_blank" class="">https://github.com/<wbr class="">apple/swift-evolution/blob/<wbr class="">master/proposals/0192-non-<wbr class="">exhaustive-enums.md</a>]</div><div class=""><br class=""></div><div class="">Whew! Thanks for your feedback, everyone. On the lighter side of feedback—naming things—it seems that most people seem to like '<b class="">@frozen</b>', and that does in fact have the connotations we want it to have. I like it too.</div><div class=""><br class=""></div><div class="">More seriously, this discussion has convinced me that it's worth including what the proposal discusses as a <b class="">'future' case</b>. The key point that swayed me is that this can produce a <i class="">warning</i> when the switch is missing a case rather than an <i class="">error,</i> which both provides the necessary compiler feedback to update your code and allows your dependencies to continue compiling when you update to a newer SDK. I know people on both sides won't be 100% satisfied with this, but does it seem like a reasonable compromise?</div><div class=""><br class=""></div><div class="">The next question is how to spell it. I'm leaning towards `unexpected case:`, which (a) is backwards-compatible, and (b) also handles "private cases", either the fake kind that you can do in C (as described in the proposal), or some real feature we might add to Swift some day. `unknown case:` isn't bad either.</div><div class=""><br class=""></div><div class="">I too would like to just do `unknown:` or `unexpected:` but that's technically a source-breaking change:</div><div class=""><br class=""></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class=""><div class="">switch foo {</div><div class="">case bar:</div><div class=""> unknown:</div><div class=""> while baz() {</div><div class=""> while garply() {</div><div class=""> if quux() {</div><div class=""> break unknown</div><div class=""> }</div><div class=""> }</div><div class=""> }</div><div class="">}</div></blockquote><div class=""><br class=""></div><div class="">Another downside of the `unexpected case:` spelling is that it doesn't work as part of a larger pattern. I don't have a good answer for that one, but perhaps it's acceptable for now.</div><div class=""><br class=""></div><div class="">I'll write up a revision of the proposal soon and make sure the core team gets my recommendation when they discuss the results of the review.</div><div class=""><br class=""></div><div class="">---</div><div class=""><br class=""></div><div class=""><div class="">I'll respond to a few of the more intricate discussions tomorrow, including the syntax of putting a new declaration inside the enum rather than outside. Thank you again, everyone, and happy new year!</div></div></div></blockquote><div class=""><br class=""></div><div class="">I do like this spelling of `@frozen`, and `unknown case` looks perfectly cromulent to me. If this is the path to go down, I'd urge more explicit design as to what happens when `unknown case` and `default` are mixed. I would imagine the most consistent design would be:</div><div class=""><br class=""></div><div class="">`unknown case` should allow `default` to be omitted if the switch is otherwise exhaustive, obviously.</div><div class="">`default` should allow `unknown case` to be omitted, just like any other case may then be omitted.</div><div class="">`unknown case` before `default` should be allowed, just like any other case before `default`; in that case, only known cases not otherwise matched reach the `default`.</div><div class="">`default` before `unknown case` makes the latter unreachable, just like any other case after `default`.</div><div class=""><br class=""></div><div class="">The issue here remains that of testability. I wonder if, for such purposes, unknown case should be instantiable when testably imported, with some grammar. In its simplest and yet most exotic form, we could imagine code that testably imports the enum to be allowed to instantiate any made-up case whatsoever (e.g., `@testable import Foo.MyEnum; let x = MyEnum.asdfasdfasdfNonexistent`).</div></div></div></div></div></blockquote><div><br class=""></div><div>What should happen when an unknown case instantiated via a testability mechanism is passed to the library that vended the enum (which is able to truly exhaustively switch over the enum)? I would like to see a solution to the testability problem and answering this question seems to be the most difficult part of finding a solution. The best answer is not obvious to me.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><div class=""><br class=""></div></div></div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>