Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch on implicitly unwrapped optional enum variable should not require a .none case #74515

Open
ewegener1 opened this issue Jun 18, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. pattern matching Feature: pattern matching type checker Area → compiler: Semantic analysis

Comments

@ewegener1
Copy link

Description

When we switch on an implicitly unwrapped optional enum variable, a .none case should not be required because the enum variable should be unwrapped before the switch happens. Hence the .none case should not be reachable.

Reproduction

The following code does not compile. The compiler wants me to add a .none case when switching on an implicitly unwrapped optional variable.

import Foundation

enum SomeEnum {
    case someCase
}

class SomeClass {
    var implicityUnwrappedEnum: SomeEnum! // note the exclamation mark here

    func main() {
        switch implicityUnwrappedEnum {
        case .someCase:
            return
        }
    }
}

Error: switch must be exhaustive
Note: add missing case: '.none'

Expected behavior

The code below compiles without errors:

import Foundation

enum SomeEnum {
    case someCase
}

class SomeClass {
    var implicityUnwrappedEnum: SomeEnum!

    func main() {
        switch implicityUnwrappedEnum {
        case .someCase:
            return
        }
    }
}

Environment

5

Additional information

No response

@ewegener1 ewegener1 added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jun 18, 2024
@hborla hborla added type checker Area → compiler: Semantic analysis pattern matching Feature: pattern matching and removed triage needed This issue needs more specific labels labels Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. pattern matching Feature: pattern matching type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants