<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jan 1, 2018, at 10:47 PM, Chris Lattner 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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 31, 2017, at 12:14 PM, Matthew Johnson via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">I agree that we need a solution to the problem described. I also agree that non-exhaustive is most in keeping with the overall design of Swift at module boundaries. However, I believe this proposal should be modified before being accepted</div></div></div></blockquote><div class=""><br class=""></div><div class="">Thanks for writing this up - you’ve explained a common concern in an interesting way:</div><div class=""><br class=""></div><blockquote type="cite" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">This is likely to be a relatively rare need mostly encountered by 3rd party libraries but it will happen. When it does happen it would be really unfortunate to be forced to use a `default` clause rather than something like a `future` clause which will produce an error when compiled against an SDK where the enum includes cases that are not covered. I can imagine cases where this catch-all case would need to do something <i class="">other than </i>abort the program so I do not like the `switch!` suggestion that has been discussed. The programmer should still be responsible for determining the behavior of unknown cases.</div></div></blockquote><div class="">..</div><div class=""><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">While library authors have a legitimate need to reserve the right to introduce new cases for some enums this need can be met without taking away a useful tool for generating static compiler errors when code does not align with intent (in this case, the intent being to cover all known cases). Switch statements working with these kinds of enums should be required to cover unknown cases but should be able to do so while still being statically checked with regards to known cases. </div></div></blockquote><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><br class=""></div></div></div></div><div class="">I think that this could be the crux of some major confusion, the root of which is the difference between source packages and binary packages that are updated outside your control (e.g. the OS, or a dynamic library that is updated independently of your app like a 3rd party plugin). Consider:</div><div class=""><br class=""></div><div class="">1) When dealing with independently updated binary packages, your code *has* to implement some behavior for unexpected cases if the enum is non-exhaustive. It isn’t acceptable to not handle that case, and it isn’t acceptable to abort because then your app will start crashing when a new OS comes out. You have to build some sort of fallback into your app.</div><div class=""><br class=""></div><div class="">2) When dealing with a source package that contributes to your app (e.g. through SwiftPM), *YOU* control when you update that package, and therefore it is entirely reasonable to exhaustively handle enums even if that package owner didn’t “intend” for them to be exhaustive. When *you* chose to update the package, you get the “unhandled case” error, and you have maximal “knowability” about the package’s behavior.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">It seems that your concern stems from the fact that the feature as proposed is aligned around module boundaries, and therefore overly punishes source packages like #2. I hope you agree that in case #1, that the feature as proposed is the right and only thing we can do: you really do have to handle unknown future cases somehow.</div><div class=""><br class=""></div><div class="">If I’m getting this right, then maybe there is a variant of the proposal that ties the error/warning behavior to whether or not a module is a source module vs a binary module. The problem with that right now is that we have no infrastructure in the language to know this…</div></div></div></div></blockquote><br class=""></div><div>YES 👏. This is the conclusion I’ve been coming to as well as I’ve been mulling it over.</div><div><br class=""></div><div>Exhaustiveness is *only* an issue for modules that are updated independently of my app (ie, via an OS or other externally-linked library changing). Modules that are shipped with my app are unaffected with this.</div><div><br class=""></div><div>I’d really love it if the build system could know that “this module is bundled with your app and therefore switches on its enums don't need a default case but this other module isn’t bundled with the app, and so therefore switches on its enums DO needs a default case”.</div><div><br class=""></div><div>Personally, I’m falling on the side of “all enums from external modules are non-exhaustive”, but I recognize there are some cases where that’s semantically incorrect (Optional<T>, for one; NSComparisonResult for another). In those cases, I think I’d prefer to have an attribute on the enum that is overly long and scary in order to emphasize that, once shipped, this enum must never change again. Something like:</div><div><br class=""></div><div>@mustNeverEverEverChangeInAFutureRelease public enum Optional<T> {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>case none</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>case some(T)</div><div>}</div><div><br class=""></div><div>Dave</div></body></html>