mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CSDiagnostics] Detect and diagnose contextual mismatches with default value
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user