-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Typechecker] Allow matching an enum case against an optional enum without '?' #22486
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
Conversation
Is this considered a bug fix and not a language change? I guess it makes sense that the behavior is more consistent with non-enum patterns now. Can you add a test that it SILGens correctly too? |
@swift-ci Please test |
@swift-ci Please test source compatibility |
@slavapestov I have added a SILGen test.
|
Let me start by saying I am strongly against changes that add implicit conversions into the semantics of pattern matching. I believe this is a language change that needs to go through Swift Evolution, and is not a bug fix. I have articulated this in a reply to the author of the bug report on Swift Evolution in the past. |
Also, please make sure that this is well-defined and included in the test suite for this patch:
|
I consider this a bug fix because it is inconsistent that the implicit conversion in fact works via an expr pattern unless you have a pattern node in the expression. That seems inconsistent to me. As a rule of thumb, a pattern should match values whose expression form looks like the pattern with the |
I'll say the implementation looks good to me, but it'd be worth re-getting approval from the core team that this should be considered a bug fix, especially in light of @CodaFi's concerns. |
Tagging core team members: @DougGregor @rjmccall @dabrahams @lattner @airspeedswift @tkremenek |
@swift-ci Please test |
@swift-ci Please test source compatibility |
The Core Team has decided that this is a bug fix. |
@swift-ci Please test |
Build failed |
Build failed |
…en the optional is nested
…onality and use lookThroughAllOptionalTypes on it to peel off all levels of optionality if the type is a nested optional
@swift-ci Please test. |
Build failed |
@swift-ci Please test OS X. |
Build failed |
Yeesh, that took a long time to kick off. |
Looks like the tests have passed smoothly 🎉 |
Thanks @theblixguy! |
This PR lifts a restriction on switching over enum cases when the enum is an
Optional
. Previously, if the enum was optional, you had to use the?
operator to switch over the cases, otherwise an error diagnostic was emitted telling the user that the case does not exist in the enum.Now, the compiler will synthesise a
OptionalSomePattern
to match a case without a trailing?
.Example:
Resolves SR-7799.
Resolves rdar://problem/41494702