mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Diagnostics] Diagnose thowing -> non-throwing contextual mismatch
This commit is contained in:
@@ -1857,6 +1857,19 @@ bool ContextualFailure::diagnoseAsError() {
|
||||
if (diagnoseConversionToBool())
|
||||
return true;
|
||||
|
||||
auto *fnType1 = getFromType()->getAs<FunctionType>();
|
||||
auto *fnType2 = getToType()->getAs<FunctionType>();
|
||||
|
||||
if (fnType1 && fnType2) {
|
||||
if (fnType1->throws() != fnType2->throws()) {
|
||||
auto throwingTy = fnType1->throws() ? fnType1 : fnType2;
|
||||
emitDiagnostic(anchor->getLoc(), diag::throws_functiontype_mismatch,
|
||||
throwingTy, throwingTy == fnType1 ? fnType2 : fnType1)
|
||||
.highlight(anchor->getSourceRange());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (auto msg = getDiagnosticFor(cs.getContextualTypePurpose(),
|
||||
/*forProtocol=*/false)) {
|
||||
diagnostic = *msg;
|
||||
|
||||
Reference in New Issue
Block a user