[Diagnostics] Diagnose thowing -> non-throwing contextual mismatch

This commit is contained in:
Pavel Yaskevich
2019-08-06 23:52:06 -07:00
parent 9526d6f90e
commit 0e9f7c0bfc

View File

@@ -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;