-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[TypeChecker] Simplify ExprPattern from Bool literals in Bool? switch #79759
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need equivalent change in CSGen I think and a test-case where a switch is used inside of a closure.
@hamishknight could you please take a look at the changes?
Approved by mistake, meant only to comment. |
@xedin Thanks for looking at it. I will investigate a CSGen change and add that test case. |
It should be pretty similar to what you already did, look at |
I'm not actually sure this needs a CSGen change, |
5e11cdd
to
1e18a68
Compare
@hamishknight Thanks! I took your suggestion and rewrote it recursively to handle any level of optionality. I also included the test case inside a closure. @xedin I explored possible changes in |
f37e0a0
to
c904b83
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Bool literals are regarded as expr patterns when switching over Optional<Bool>. Simplify the expr by converting to their optional counterparts.
c904b83
to
3649dcb
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I originally thought that this needs to happen earlier.
The source compatibility checks are failing but so far I haven't found a failure that seems related to this change. For example, https://ci.swift.org/job/swift-PR-source-compat-suite-macos/2271/artifact/swift-source-compat-suite/FAIL_SwiftLint_5.0_BuildSwiftPackage.log. Most seem related to not finding MacOS specific modules, but it looks like that sdk is being properly selected so I'm not sure. |
Those are the same failures as on main, so yeah they're unrelated |
@swift-ci please test source compatibility Debug |
Source compat failures unrelated |
Resolves: swiftlang/swift#61817.
Boolean literals are treated as
ExprPattern
s when switching overBool?
because they require implicit conversion to Optionals, resulting in them being wrapped inInjectIntoOptionalExpr
s. Consequently, they do not contribute to exhausting the switch cases.In this special case, we can instead treat them as
true?
/false?
.