Skip to content

Commit 2704b6d

Browse files
[ConstraintSystem] Diagnose ambiguity for generic parameter bindings with no fixes
1 parent 9053413 commit 2704b6d

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,14 +2763,21 @@ static bool diagnoseConflictingGenericArguments(ConstraintSystem &cs,
27632763
if (!diff.overloads.empty())
27642764
return false;
27652765

2766-
if (!llvm::all_of(solutions, [](const Solution &solution) -> bool {
2766+
bool noFixes = llvm::all_of(solutions, [](const Solution &solution) -> bool {
2767+
return solution.Fixes.empty();
2768+
});
2769+
2770+
bool allMismatches =
2771+
llvm::all_of(solutions, [](const Solution &solution) -> bool {
27672772
return llvm::all_of(
27682773
solution.Fixes, [](const ConstraintFix *fix) -> bool {
27692774
return fix->getKind() == FixKind::AllowArgumentTypeMismatch ||
27702775
fix->getKind() == FixKind::AllowFunctionTypeMismatch ||
27712776
fix->getKind() == FixKind::AllowTupleTypeMismatch;
27722777
});
2773-
}))
2778+
});
2779+
2780+
if (!noFixes && !allMismatches)
27742781
return false;
27752782

27762783
auto &DE = cs.getASTContext().Diags;
@@ -2923,6 +2930,11 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
29232930
if (solutions.empty())
29242931
return false;
29252932

2933+
SolutionDiff solutionDiff(solutions);
2934+
2935+
if (diagnoseConflictingGenericArguments(*this, solutionDiff, solutions))
2936+
return true;
2937+
29262938
if (auto bestScore = solverState->BestScore) {
29272939
solutions.erase(llvm::remove_if(solutions,
29282940
[&](const Solution &solution) {
@@ -2938,11 +2950,6 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
29382950
return false;
29392951
}
29402952

2941-
SolutionDiff solutionDiff(solutions);
2942-
2943-
if (diagnoseConflictingGenericArguments(*this, solutionDiff, solutions))
2944-
return true;
2945-
29462953
if (diagnoseAmbiguityWithEphemeralPointers(*this, solutions))
29472954
return true;
29482955

0 commit comments

Comments
 (0)