-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CodeComplete] Properly handle if
/switch
expressions
#67563
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ahoppen
reviewed
Jul 27, 2023
hamishknight
commented
Jul 31, 2023
hamishknight
commented
Jul 31, 2023
dc0edf4
to
c7ef69f
Compare
xedin
approved these changes
Jul 31, 2023
d521a7c
to
30429f8
Compare
@swift-ci Please SourceKit stress test |
ahoppen
approved these changes
Jul 31, 2023
Instead of querying the ConstraintSystem, query the Solution instead, as the ConstraintSystem is not necessarily in the same state as when the solution was produced.
Split out the part of TypeCheckFunctionBodyRequest that inserts and removes implicit returns.
Run PreCheckFunctionBodyRequest to ensure we insert an implicit return for an if/switch if needed, and ensure we don't try and type-check an element in a SingleValueStmtExpr separately, as it should be type-checked as a whole by the constraint system. This ensures we can propagate a contextual type from outside an if/switch expression for code completion.
…xprs Skip type-checking multi-statement branches if the completion is in a single-expression branch, and skip type-checking the expression as a whole if the completion is in a multi-statement branch.
…f/switch expr Fix an issue uncovered by the stress tester where the brace element skipping logic could still attempt to skip a single-expression body of an if/switch expr.
@swift-ci please test |
@swift-ci please SourceKit stress test |
Stress tester uncovered an issue, fixed in latest commit. This will also be improved by the work in #67454 since we'll no longer use free-standing single-expression bodies to model the results of an if/switch expr, we'll use a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Run PreCheckFunctionBodyRequest to ensure we insert an implicit return for an
if
/switch
if needed, and ensure we don't try and type-check an element in a SingleValueStmtExpr separately, as it should be type-checked as a whole by the constraint system. This ensures we can propagate a contextual type from outside anif
/switch
expression for code completion.