Skip to content

Commit 2508e6c

Browse files
committed
[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.
1 parent 17d3335 commit 2508e6c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/Sema/TypeCheckCodeCompletion.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,11 @@ fallbackTypeCheck(DeclContext *DC) {
10571057
}
10581058

10591059
static Type getTypeForCompletion(const constraints::Solution &S, Expr *E) {
1060+
if (!S.hasType(E)) {
1061+
assert(false && "Expression wasn't type checked?");
1062+
return nullptr;
1063+
}
1064+
10601065
auto &CS = S.getConstraintSystem();
10611066

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

0 commit comments

Comments
 (0)