Skip to content

Commit 2924ce0

Browse files
authored
Merge pull request #70409 from xedin/rdar-119001449
[ConstraintSystem] Run `salvage` even if diagnostics are suppressed
2 parents 5763f9f + 00bb7d3 commit 2924ce0

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,14 +1515,6 @@ ConstraintSystem::solve(SyntacticElementTarget &target,
15151515
LLVM_FALLTHROUGH;
15161516

15171517
case SolutionResult::UndiagnosedError:
1518-
/// If we have a SolutionCallback, we are inspecting constraint system
1519-
/// solutions directly and thus also want to receive ambiguous solutions.
1520-
/// Hence always run the second (salvaging) stage.
1521-
if (shouldSuppressDiagnostics() && !Context.SolutionCallback) {
1522-
solution.markAsDiagnosed();
1523-
return llvm::None;
1524-
}
1525-
15261518
if (stage == 1) {
15271519
diagnoseFailureFor(target);
15281520
reportSolutionsToSolutionCallback(solution);

lib/Sema/ConstraintSystem.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4389,6 +4389,10 @@ SolutionResult ConstraintSystem::salvage() {
43894389
return SolutionResult::forSolved(std::move(viable[0]));
43904390
}
43914391

4392+
if (shouldSuppressDiagnostics())
4393+
return viable.empty() ? SolutionResult::forUndiagnosedError()
4394+
: SolutionResult::forAmbiguous(viable);
4395+
43924396
// FIXME: If we were able to actually fix things along the way,
43934397
// we may have to hunt for the best solution. For now, we don't care.
43944398

@@ -5228,7 +5232,7 @@ static bool diagnoseContextualFunctionCallGenericAmbiguity(
52285232

52295233
bool ConstraintSystem::diagnoseAmbiguityWithFixes(
52305234
SmallVectorImpl<Solution> &solutions) {
5231-
if (solutions.empty())
5235+
if (solutions.empty() || shouldSuppressDiagnostics())
52325236
return false;
52335237

52345238
SolutionDiff solutionDiff(solutions);

lib/Sema/TypeCheckCodeCompletion.cpp

Lines changed: 9 additions & 7 deletions
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)