Skip to content

Commit c01bff7

Browse files
committed
[code-completion] Allow ErrorType in solution to avoid assertion failure
When CSGen encounters an error it may set a type to ErrorType, but the system will still "solve".
1 parent d822c39 commit c01bff7

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,10 +1631,14 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
16311631
auto &solution = viable[0];
16321632
Type exprType = solution.simplifyType(*this, expr->getType());
16331633

1634-
assert(exprType && !exprType->hasError() && "erroneous solution?");
1635-
assert(!exprType->hasTypeVariable() &&
1634+
assert(exprType && !exprType->hasTypeVariable() &&
16361635
"free type variable with FreeTypeVariableBinding::GenericParameters?");
16371636

1637+
if (exprType->hasError()) {
1638+
recoverOriginalType();
1639+
return None;
1640+
}
1641+
16381642
// Dig the declaration out of the solution.
16391643
auto semanticExpr = expr->getSemanticsProvidingExpr();
16401644
auto topLocator = cs.getConstraintLocator(semanticExpr);

validation-test/IDE/crashers/108-swift-typechecker-typecheckcompletionsequence.swift

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
func c{case
3+
let a#^A^#}

0 commit comments

Comments
 (0)