<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 14, 2018, at 09:36, Vladimir.S &lt;<a href="mailto:svabox@gmail.com" class="">svabox@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class=""><br class="">On 12.01.2018 21:38, Jordan Rose wrote:<br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">On Jan 12, 2018, at 06:49, Michel Fortin via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a> &lt;<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>&gt;&gt; wrote:<br class=""><br class=""><blockquote type="cite" class="">Le 12 janv. 2018 à 4:44, Vladimir.S via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a> &lt;<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>&gt;&gt; a écrit :<br class=""><br 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 &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a> &lt;<a href="mailto:swift-evolution@swift.org" class="">mailto:swift-evolution@swift.org</a>&gt;&gt; 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. &nbsp;They are patterns, so it naturally falls out.<br class="">If we go with the “unknown default:” / “unknown case:" &nbsp;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? &nbsp;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="">&nbsp;case .one: ..<br class="">&nbsp;case .two: ..<br class="">&nbsp;unknown default: .. &nbsp;// 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="">&nbsp;case .one: ..<br class="">&nbsp;case .two: ..<br class="">&nbsp;unknown default: .. &nbsp;// 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?<br class=""></blockquote><br class="">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.<br class=""><br 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.<br class=""></blockquote>As mentioned in "Future directions", my recommendation to anyone planning to write a proposal for non-public cases is to go with the former, which would keep it from infecting the design.<br class=""></blockquote><br class="">Thank you for the comment!<br class="">From proposal:<br class="">"Were such a proposal to be written, I advise that a frozen enum not be permitted to have non-public cases."<br class=""><br class="">OK. Seems logically for frozen enum(imported from another module) to not have non-public cases, as such cases most likely will be added later during the evaluation of the library(external module) - so such enum should not be frozen then.<br class=""><br class="">I'd like to discuss how current decision will fit into the (possible) future 'private cases' in enum.<br class=""><br class="">1. Non-frozen enum with private cases in the same module.<br class=""><br class="">It seems like we'll need to write<br class="">switch val {<br class=""> case .one : ..<br class=""> case .two : ..<br class=""> unknown default: .. // for private cases, even 'val' can't have 'future' cases<br class="">}<br class=""><br class="">So, 'unknown default' will mean not just 'future cases', but 'future cases and private cases'.<br class=""></div></div></blockquote><div><br class=""></div><div>Interesting. I didn't think about that; in the original proposal without any warnings, you just had to use 'default'. But it does make sense, and whoever proposes private cases will have to mention that.</div><div><br class=""></div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class="">2. Non-frozen enum with private cases in another module.<br class=""><br class="">In this case, if we want exhaustive switch, we need to use 'unknown default'. But I feel like known but private cases are not the same as future public cases for the 'consumer' of that enum, no?<br class=""><br class="">I mean, when making a decision what to do inside 'unknown default' - isn't it important to know what is the "event" - new public case or private(even "known") case? I'm thinking about something like this:<br class=""><br class="">let val = getSomeNonFrozenEnumResultFromLibrary()<br class="">switch val {<br class=""> &nbsp;case .one : ... // process the val on our side<br class=""> &nbsp;case .two : ... // process the val on our side<br class=""><br class=""> &nbsp;private default : sendValueBackToLibraryToProcess(val) // not interested, calling some special handler<br class=""> &nbsp;future default : .. // somehow react on important new case introduced in library. for example, show "please update the app" for the user and cancels the current operation<br class="">}<br class=""><br class="">I don't think we need to think about "future private" cases, as we don't have access to them in any case, so current and future private cases are not distinguishable for us.<br class=""><br class="">I'm not sure if we should distinct future cases and private cases on 'switch' side, but I think we should discuss this now for taking a correct decision regarding 'unknown default' etc.<br class=""></div></div></blockquote><div><br class=""></div><div>I think this distinction is both too fine-grained to be useful and not possible to implement. You don't get to see whether an enum has private cases or not, so <i class="">every</i>&nbsp;switch on a non-frozen enum from another module would have to have both of these, and then when the library is actually updated but your app isn't recompiled, you can't tell whether the case you're just now seeing is a new private case or a new public case.</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class="">P.S. FWIW I agree with Chris Lattner that 'unknown default' fits into Swift syntax and mental model much better than 'unknown case'. This handler is for default reacting on _number_ of unknown cases, not for reacting on some _specific_ case, like other 'case xxx:' handlers. Are we going to discuss this and select the better name? Or most of us not agree that 'unknown case' is the best?</div></div></blockquote><br class=""></div><div>*shrug* That's on the core team to decide when the second review period is over. Nobody has convinced me yet that `unknown default` is better than `unknown case`, but the particular spelling here isn't a key part of the proposal. (I just replied to Chris with my reasoning for preferring `unknown case`.)</div><div><br class=""></div><div>Jordan</div><br class=""></body></html>