[Diagnostics] Add a diagnostic for incorrect use of trailing closures

This commit is contained in:
Pavel Yaskevich
2019-10-31 20:58:01 -07:00
parent d87d22d336
commit 6bb659c5a3
3 changed files with 30 additions and 1 deletions

View File

@@ -5491,3 +5491,20 @@ bool ExtraneousCallFailure::diagnoseAsError() {
removeParensFixIt(diagnostic);
return true;
}
bool InvalidUseOfTrailingClosure::diagnoseAsError() {
auto *anchor = getAnchor();
auto &cs = getConstraintSystem();
emitDiagnostic(anchor->getLoc(), diag::trailing_closure_bad_param,
getToType())
.highlight(anchor->getSourceRange());
if (auto overload = getChoiceFor(cs.getCalleeLocator(getLocator()))) {
if (auto *decl = overload->choice.getDeclOrNull()) {
emitDiagnostic(decl, diag::decl_declared_here, decl->getFullName());
}
}
return true;
}