<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">It will be better to use `fatalError()` in `default` part that you think never be needed.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default"><font face="georgia, serif">default:</font><br></div><div class="gmail_default"><font face="georgia, serif">fatalError("This should never happen!")</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">Zhaoxin</font></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 29, 2016 at 11:25 AM, Dave Abrahams via swift-dev <span dir="ltr"><<a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
on Sun Nov 27 2016, Slava Pestov <swift-dev-AT-swift.org> wrote:<br>
<br>
>> On Nov 27, 2016, at 4:32 PM, David Sweeris via swift-dev <<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a>> wrote:<br>
>><br>
>>><br>
>>> On Nov 26, 2016, at 5:25 PM, Robert Widmann via swift-dev <<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a><br>
</span><div><div class="h5">> <mailto:<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a>>> wrote:<br>
>>><br>
><br>
>>> Hello all,<br>
>>><br>
>>> I’ve seen and been a part of a number of conversations recently where talk of planning for “resilient enums”, or even just authors that ship frameworks that will eventually offer a binary option that export enum-based APIs. The consensus seems to be that the only safe way to deal with this situation is to always cover a `switch` statement with a default, regardless of whether the totality checker thinks you’ve covered all cases. Currently, the compiler warns when this is the case, as in stdlib<br>
>>><br>
>>> extension ProcessTerminationStatus {<br>
>>> var isSwiftTrap: Bool {<br>
>>> switch self {<br>
>>> case .exit(_):<br>
>>> return false<br>
>>> case .signal(let signal):<br>
>>> return CInt(signal) == SIGILL || CInt(signal) == SIGTRAP<br>
>>> default:<br>
>>> // This default case is needed for standard library builds where<br>
>>> // resilience is enabled<br>
>>> return false<br>
>>> }<br>
>>> }<br>
>>> }<br>
>>><br>
>>> I think this warning doesn’t actually serve a purpose and I’d like to remove it, or at the very<br>
> least curb it. Currently, I see three paths forward:<br>
>>><br>
>>> 1) Do nothing.<br>
>>> 2) Completely remove the diagnostic<br>
>>> 3) Only emit the diagnostic when the case-tree is switching over enum(s) declared inside the<br>
> current module.<br>
>><br>
>> Has the “resilient enum” thing been finalized, or is this kind of code just a preventative<br>
> measure?<br>
>><br>
>> Also, if “resilience” is a compiler flag, there's a fourth option: Disable the warning on builds<br>
> that have “resilience” enabled.<br>
><br>
> The warning is already gone (and the default cause is required) when<br>
> the standard library and overlays are built with resilience<br>
> enabled. The issue is that resilience is off by default.<br>
><br>
> I agree the warning is annoying; we should figure out something.<br>
<br>
</div></div>There should also be a way to write code that will compile without<br>
warnings whether or not you have resilience enabled. ;-)<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
-Dave<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
______________________________<wbr>_________________<br>
swift-dev mailing list<br>
<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-dev" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-dev</a><br>
</div></div></blockquote></div><br></div>