[CSDiagnostics] Detect and diagnose contextual mismatches with default value

This commit is contained in:
Pavel Yaskevich
2022-02-18 18:50:14 -08:00
parent aa286b7bf4
commit 82b955b93c
6 changed files with 115 additions and 1 deletions

View File

@@ -4870,6 +4870,25 @@ bool ConstraintSystem::repairFailures(
if (hasFixFor(loc, FixKind::RemoveExtraneousArguments))
return true;
// If the argument couldn't be found, this could be a default value
// type mismatch.
if (!simplifyLocatorToAnchor(loc)) {
auto *calleeLocator = getCalleeLocator(loc);
unsigned paramIdx =
loc->castLastElementTo<LocatorPathElt::ApplyArgToParam>()
.getParamIdx();
if (auto overload = findSelectedOverloadFor(calleeLocator)) {
if (auto *decl = overload->choice.getDeclOrNull()) {
if (getParameterList(decl)->get(paramIdx)->getTypeOfDefaultExpr()) {
conversionsOrFixes.push_back(
IgnoreDefaultExprTypeMismatch::create(*this, lhs, rhs, loc));
break;
}
}
}
}
conversionsOrFixes.push_back(
AllowArgumentMismatch::create(*this, lhs, rhs, loc));
break;
@@ -12438,7 +12457,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
: SolutionKind::Solved;
}
case FixKind::AllowArgumentTypeMismatch: {
case FixKind::AllowArgumentTypeMismatch:
case FixKind::IgnoreDefaultExprTypeMismatch: {
auto impact = 2;
// If there are any other argument mismatches already detected for this
// call, we increase the score even higher so more argument fixes means