Skip to content

[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 5 commits into from
Aug 2, 2023

Conversation

hamishknight
Copy link
Contributor

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.

@hamishknight hamishknight force-pushed the complete branch 2 times, most recently from dc0edf4 to c7ef69f Compare July 31, 2023 15:10
@hamishknight hamishknight force-pushed the complete branch 3 times, most recently from d521a7c to 30429f8 Compare July 31, 2023 18:25
@ahoppen
Copy link
Member

ahoppen commented Jul 31, 2023

@swift-ci Please SourceKit stress test

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.
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight
Copy link
Contributor Author

@swift-ci please SourceKit stress test

@hamishknight
Copy link
Contributor Author

hamishknight commented Aug 1, 2023

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 ThenStmt, which is more easy to handle.

@hamishknight hamishknight deleted the complete branch August 2, 2023 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants