Merge pull request #30022 from LucianoPAlmeida/SR-9839-convention-function-conversions-fail

[SR-9839] Fixes ambiguity in convention function argument inference
This commit is contained in:
Pavel Yaskevich
2020-04-08 15:48:51 -07:00
committed by GitHub
2 changed files with 36 additions and 7 deletions

View File

@@ -2770,14 +2770,22 @@ static bool diagnoseConflictingGenericArguments(ConstraintSystem &cs,
if (!diff.overloads.empty())
return false;
if (!llvm::all_of(solutions, [](const Solution &solution) -> bool {
bool noFixes = llvm::all_of(solutions, [](const Solution &solution) -> bool {
const auto score = solution.getFixedScore();
return score.Data[SK_Fix] == 0 && solution.Fixes.empty();
});
bool allMismatches =
llvm::all_of(solutions, [](const Solution &solution) -> bool {
return llvm::all_of(
solution.Fixes, [](const ConstraintFix *fix) -> bool {
return fix->getKind() == FixKind::AllowArgumentTypeMismatch ||
fix->getKind() == FixKind::AllowFunctionTypeMismatch ||
fix->getKind() == FixKind::AllowTupleTypeMismatch;
});
}))
});
if (!noFixes && !allMismatches)
return false;
auto &DE = cs.getASTContext().Diags;
@@ -2930,6 +2938,11 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
if (solutions.empty())
return false;
SolutionDiff solutionDiff(solutions);
if (diagnoseConflictingGenericArguments(*this, solutionDiff, solutions))
return true;
if (auto bestScore = solverState->BestScore) {
solutions.erase(llvm::remove_if(solutions,
[&](const Solution &solution) {
@@ -2945,11 +2958,6 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
return false;
}
SolutionDiff solutionDiff(solutions);
if (diagnoseConflictingGenericArguments(*this, solutionDiff, solutions))
return true;
if (diagnoseAmbiguityWithEphemeralPointers(*this, solutions))
return true;