[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

@@ -7966,3 +7966,27 @@ bool SwiftToCPointerConversionInInvalidContext::diagnoseAsError() {
paramType, callee->getDescriptiveKind(), callee->getName());
return true;
}
bool DefaultExprTypeMismatch::diagnoseAsError() {
auto *locator = getLocator();
unsigned paramIdx =
locator->castLastElementTo<LocatorPathElt::ApplyArgToParam>()
.getParamIdx();
emitDiagnostic(diag::cannot_convert_default_value_type_to_argument_type,
getFromType(), getToType(), paramIdx);
auto overload = getCalleeOverloadChoiceIfAvailable(locator);
assert(overload);
auto *PD = getParameterList(overload->choice.getDecl())->get(paramIdx);
auto note = emitDiagnosticAt(PD->getLoc(), diag::default_value_declared_here);
if (auto *defaultExpr = PD->getTypeCheckedDefaultExpr()) {
note.highlight(defaultExpr->getSourceRange());
}
return true;
}