<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=""><div class=""><div><blockquote type="cite" class=""><div class="">Le 12 janv. 2018 à 4:44, Vladimir.S via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><div class="">On 12.01.2018 10:30, Chris Lattner via swift-evolution wrote:<br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">On Jan 11, 2018, at 11:15 PM, Jean-Daniel via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class="">A question about the new #unknown behavior. Is it intended to be used for error handling too ?<br class="">Will it be possible to use in catch clause ?<br class=""></blockquote>If we go with the #unknown approach, then yes of course it will work in catch clauses. They are patterns, so it naturally falls out.<br class="">If we go with the “unknown default:” / “unknown case:" approach, then no, this has nothing to do with error handling.<br class="">IMO, this pivots on the desired semantics for “unknown cases in enums”: if you intentionally try to match on this, do we get a warning or error if you don’t handle all the cases? If we can get to consensus on that point, then the design is pretty obvious IMO.<br class=""></blockquote><br class="">For me the other question is what "all the cases" means for enum with private cases(if we'll have them). I.e. if switch contains all the "public" cases of frozen enum - does this mean "all the cases" were processed? As I understand, the answer is no, because we *can* have 'private' case value here and so we need to react to this. How switch will look in this case?<br class=""><br class="">switch frozenEnumWithPrivateCases {<br class=""> case .one: ..<br class=""> case .two: ..<br class=""> unknown default: .. // or 'case #unknown:' depending on our decision, or 'unknown case:' etc<br class="">}<br class="">?<br class="">But then such switch looks exactly as switch for non-frozen enum value, no? It looks like we are reacting on future new cases, while enum is frozen.<br class=""><br class="">Moreover. How the switch for non-frozed enum with private cases should looks like?<br class=""><br class="">switch nonfrozenEnumWithPrivateCases {<br class=""> case .one: ..<br class=""> case .two: ..<br class=""> unknown default: .. // or 'case #unknown:' depending on our decision, or 'unknown case:' etc<br class="">}<br class="">? But then, is that 'unknown default' for reacting on "future" cases we didn't know about during the compilation OR it is for reacting on private cases?<br class=""><br class="">Or the main idea that we don't want to separate "future" cases and "private" cases?</div></div></blockquote><div><br class=""></div><div>I think treating both as the same thing is the right idea. You also need to handle "future private" cases and "private cases that become public in the future". These are all unknown cases in the context of the switch.</div><div><br class=""></div><div><div class="">So an enum with private cases can't be switched exhaustively outside of its module. Thus, @frozen would need to forbid private cases... or we need @exhaustive to forbid private cases so they can be allowed by @frozen.</div><div class=""></div></div></div></div><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">-- <br class="">Michel Fortin</div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span style="text-align: -webkit-auto;" class=""><a href="https://michelf.ca" class="">https://michelf.ca</a></span></div></span></div></span></div></span></div></div></div></div>
</div>
<br class=""></body></html>