-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SourceKit] Determine correctly whether typed variables in if/guard/while-let
-statements have explicit type annotations
#38084
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
- Add VariableType test case for guarded variables - Add if-let to VariableType test case - Add while-let test case for VariableType - Test pattern matching with VariableType - Test guard/while-case-let with VariableType
8d57e04
to
157a644
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.
I think it might be worth adding the check to getTypeReprOrParentPatternTypeRepr
. It seems generic enough to me that other user’s of the API could also benefit from it.
Or was there a specific reason why you didn’t do that?
It would change the semantics of the method slightly (by not just considering the parent pattern), therefore I wasn't sure whether this should be included. |
I think changing the semantics of I would also leave the implicitness check unless there’s a specific reason to include it that you can explain. Just makes the code simpler and more generic. |
As suggested during PR review. This mechanism seems to be general enough to fit into getTypeReprOrParentPatternRepr.
e0d1d98
to
b33a202
Compare
@swift-ci Please smoke test |
Not entirely sure about the CI failure, but it seems unrelated to the PR? |
Yes, the CI failure is unrelated. I’ll try again later. |
@swift-ci Please smoke test Linux |
1 similar comment
@swift-ci Please smoke test Linux |
As noted in swiftlang/sourcekit-lsp#408 (comment),
if/guard/while-let
s are currently (incorrectly) always reported as having no explicit type annotation as theTypedPattern
is not the top-level-pattern in such declarations. Consider the following example:Here we get the following AST:
sourcekitd-test
therefore reports(explicit type: 0)
despite an explicit annotation being present:This PR fixes the issue by including an implicitly generated
OptionalSomePattern
as a special case inVariableTypeCollector
and also adds tests to verify that these cases are handled correctly.cc @ahoppen