-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Optional boolean doesn't satisfy switch exhaustivity with literal case statements #61817
Comments
|
Unfortunately, we cannot consider this to be exhaustive because these are expression patterns that are subject to the https://github.com/apple/swift/blob/main/stdlib/public/core/Policy.swift#L324 |
|
To make these patterns again, you can spell them as |
|
Ok thanks for clarifying that, @CodaFi. However, even if the general |
|
True, we could add an extremely special case that detected an arbitrary number of optional injections applied to a ~= with a literal at the root. And we'd have to make sure it was the ~= in the stdlib specifically. |
|
hey! I want to work on this issue, but I am new to open source . |
|
Hi Ashutosh, have you read the README? |
|
Hey @ashuthe1 are you working on this? @AnthonyLatsis I have read the docs, build the swift project on my machine, kind of understand the problem statement. Would love to get started with this! |
|
Hello @swiftlysingh, you are welcome to give it a go but I wouldn’t say this issue is a great candidate for a very first contribution if you’re new to this sort of stuff. Not without some prior reading and research, at least. |
@CodaFi I believe this is an actual bug, because without the optional the boolean literals would have resolved to |
|
I am in for some research, if it is required. I come across this issue while going through the "good first issue" label. Which issue would you recommend for getting started? @AnthonyLatsis |
|
We have a list of external resources with some great introductory blog posts and talks. The AST section is generally a good place to start with in terms of implementation.
This is a special GitHub label, so we cannot customize the name. We use it to mark onboarding issues in general — both the ones that are best suited for first-time contributions, and the ones that warrant basic familiarity with a certain area.
Something like this, this or this. This one should be alright with a bit of reading. |
|
Looking into this issue. Sorry for the delayed response. Will be reading up on blogs and talks from the external resources as well! |
|
enum BoolEnum { func over(boolEnum: BoolEnum?) { we can add a case of none and than try it, might resolve this issue. |
|
Hey ! Is anyone currently looking at this issue ? 👀 If not, I'd to try resolving it 🤩 |
Describe the bug
When
switching over an optional boolean withtrueandfalseliterals, an error diagnostic is produced claiming that the switch statement is not exhaustive. This is inconsistent with other pattern matchable value types which unwraps the optional to perform a match.Steps To Reproduce
Expected behavior
No diagnostic should be produced, as the switch is exhaustive. For example if we redefine a
Bool-likeenum, the exhaustivity checker works correctly and no diagnostic is produced:Screenshots
Environment (please fill out the following information)
The text was updated successfully, but these errors were encountered: