Skip to content

[CodeComplete] Don't crash if solution doesn't contain a type for the parsed expression #39410

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 1 commit into from
Sep 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[CodeComplete] Don't crash if solution doesn't contain a type for the…
… parsed expression

In rdar://82027315 we are trying to retrieve the type of an `ASTNode` that doesn’t have a type associated with it in the solution from `getTypeForCompletion`.

This shouldn’t happen but we shouldn’t crash because of it, either. Since we already have handling logic for null types returned by `getTypeForCompletion` in place, I’m adding a check if the solution contains a type for the given node. If not, we’re causing an assertion failure and are returning a null type in non-assert builds.
  • Loading branch information
ahoppen committed Sep 23, 2021
commit 2508e6ca04a4141254f0a4727579d23274385ac5
5 changes: 5 additions & 0 deletions lib/Sema/TypeCheckCodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,11 @@ fallbackTypeCheck(DeclContext *DC) {
}

static Type getTypeForCompletion(const constraints::Solution &S, Expr *E) {
if (!S.hasType(E)) {
assert(false && "Expression wasn't type checked?");
return nullptr;
}

auto &CS = S.getConstraintSystem();

// To aid code completion, we need to attempt to convert type placeholders
Expand Down