[swift-users] Handle deprecated enum cases from a library
Dennis Weissmann
dennis at dennisweissmann.me
Mon Nov 6 05:47:36 CST 2017
Hey Charles,
Thanks for going through this with me :)
I'm not sure whether or not this is a compiler bug (that's partially why I posted it here), although I have the feeling that *something* is definitely wrong.
Funnily enough, the following code shows 3 compiler warnings which are incorrect:
private func handleLocalAuthenticationError(_ error: LAError) {
switch error.code {
case .userCancel, .appCancel, .systemCancel:
print(".userCancel, .appCancel, .systemCancel")
case .authenticationFailed:
print(".authenticationFailed")
case .passcodeNotSet:
print(".passcodeNotSet")
case .biometryNotEnrolled, .touchIDNotEnrolled: // Compiler: Case will never be executed
print(".biometryNotEnrolled, .touchIDNotEnrolled")
case .biometryNotAvailable, .touchIDNotAvailable: // Compiler: Case will never be executed
print(".biometryNotAvailable, .touchIDNotAvailable")
case .biometryLockout, .touchIDLockout: // Compiler: Case will never be executed
print(".biometryLockout, .touchIDLockout")
case .userFallback:
print(".userFallback")
case .invalidContext:
print(".invalidContext")
case .notInteractive:
print(".notInteractive")
}
}
let error = LAError(.touchIDLockout)
handleLocalAuthenticationError(error)
When you run it in a playground, you can see that the case *gets* executed.
- Dennis
> On Nov 5, 2017, at 7:13 PM, Charles Srstka <cocoadev at charlessoft.com> wrote:
>
>> On Nov 5, 2017, at 10:39 AM, Dennis Weissmann <dennis at dennisweissmann.me <mailto:dennis at dennisweissmann.me>> wrote:
>>
>>> You can delete the default case here, and your switch will still be exhaustive
>> That's exactly my problem! It is *not*.
>>
>> When I delete the default clause, the compiler warns that the switch is not exhaustive and fixits suggest to add the "missing" deprecated cases.
>>
>> - Dennis
>
> Hi Dennis,
>
> Ah, I see—although the switch should be considered exhaustive since you have covered all the possible cases, the compiler is claiming that it is not. I would probably consider this to be a compiler bug. Have you considered filing a report at bugs.swift.org <http://bugs.swift.org/>?
>
> Charles
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20171106/e383e7f3/attachment.html>
More information about the swift-users
mailing list