[swift-users] Handle deprecated enum cases from a library

Charles Srstka cocoadev at charlessoft.com
Mon Nov 6 10:20:06 CST 2017


> On Nov 6, 2017, at 5:47 AM, Dennis Weissmann <dennis at dennisweissmann.me> wrote:
> 
> 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

I’d say that this sort of damned-if-you-do-damned-if-you-don’t behavior that emits a warning no matter what you do has to be a compiler bug. Post it on bugs.swift.org <http://bugs.swift.org/> and hopefully it will get fixed.

Charles

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20171106/31b17206/attachment.html>


More information about the swift-users mailing list