Skip to content

Commit 00bb7d3

Browse files
committed
[CodeCompletion] Use solveForCodeCompletion in getTypeOfExpressionWithoutApplying
Using `ConstraintSystem::solve` would mean re-solving now since `SuppressDiagnostics` doesn't suppress `salvage`.
1 parent 09a5b99 commit 00bb7d3

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/Sema/TypeCheckCodeCompletion.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ using namespace constraints;
5959

6060
static Type
6161
getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
62-
ConcreteDeclRef &referencedDecl,
63-
FreeTypeVariableBinding allowFreeTypeVariables) {
62+
ConcreteDeclRef &referencedDecl) {
6463
if (isa<AbstractClosureExpr>(dc)) {
6564
// If the expression is embedded in a closure, the constraint system tries
6665
// to retrieve that closure's type, which will fail since we won't have
@@ -95,15 +94,18 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
9594
expr->setType(Type());
9695
SyntacticElementTarget target(expr, dc, CTP_Unused, Type(),
9796
/*isDiscarded=*/false);
98-
auto viable = cs.solve(target, allowFreeTypeVariables);
99-
if (!viable) {
97+
98+
SmallVector<Solution, 2> viable;
99+
cs.solveForCodeCompletion(target, viable);
100+
101+
if (viable.empty()) {
100102
recoverOriginalType();
101103
return Type();
102104
}
103105

104106
// Get the expression's simplified type.
105107
expr = target.getAsExpr();
106-
auto &solution = (*viable)[0];
108+
auto &solution = viable.front();
107109
auto &solutionCS = solution.getConstraintSystem();
108110
Type exprType = solution.simplifyType(solutionCS.getType(expr));
109111

@@ -332,8 +334,8 @@ getTypeOfCompletionContextExpr(DeclContext *DC, CompletionTypeCheckKind kind,
332334
}
333335

334336
Type originalType = parsedExpr->getType();
335-
if (auto T = getTypeOfExpressionWithoutApplying(parsedExpr, DC,
336-
referencedDecl, FreeTypeVariableBinding::UnresolvedType))
337+
if (auto T =
338+
getTypeOfExpressionWithoutApplying(parsedExpr, DC, referencedDecl))
337339
return T;
338340

339341
// Try to recover if we've made any progress.

0 commit comments

Comments
 (0)