Skip to content

Commit 6b52016

Browse files
committed
[ConstraintSystem] Rank solutions based on overload choices only after fix diagnostics have failed
If there are multiple solutions with fixes, let's not try to rank them based on overload choices because doing so would filter out viable candidates.
1 parent e9b241f commit 6b52016

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,6 +2719,11 @@ SolutionResult ConstraintSystem::salvage() {
27192719
// Solve the system.
27202720
solveImpl(viable);
27212721

2722+
// Before removing any "fixed" solutions, let's check
2723+
// if ambiguity is caused by fixes and diagnose if possible.
2724+
if (diagnoseAmbiguityWithFixes(viable))
2725+
return SolutionResult::forAmbiguous(viable);
2726+
27222727
// Check whether we have a best solution; this can happen if we found
27232728
// a series of fixes that worked.
27242729
if (auto best = findBestSolution(viable, /*minimize=*/true)) {
@@ -2728,11 +2733,6 @@ SolutionResult ConstraintSystem::salvage() {
27282733
return SolutionResult::forSolved(std::move(viable[0]));
27292734
}
27302735

2731-
// Before removing any "fixed" solutions, let's check
2732-
// if ambiguity is caused by fixes and diagnose if possible.
2733-
if (diagnoseAmbiguityWithFixes(viable))
2734-
return SolutionResult::forAmbiguous(viable);
2735-
27362736
// FIXME: If we were able to actually fix things along the way,
27372737
// we may have to hunt for the best solution. For now, we don't care.
27382738

@@ -3071,7 +3071,7 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
30713071

30723072
if (diagnoseConflictingGenericArguments(*this, solutionDiff, solutions))
30733073
return true;
3074-
3074+
30753075
if (auto bestScore = solverState->BestScore) {
30763076
solutions.erase(llvm::remove_if(solutions,
30773077
[&](const Solution &solution) {
@@ -3087,6 +3087,9 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
30873087
return false;
30883088
}
30893089

3090+
if (solutions.size() < 2)
3091+
return false;
3092+
30903093
if (diagnoseAmbiguityWithEphemeralPointers(*this, solutions))
30913094
return true;
30923095

0 commit comments

Comments
 (0)