Skip to content

Commit 0170c89

Browse files
committed
[CSDiag] NFC: Remove obsolete @dynamicCallable diagnostics
1 parent 21a8b3c commit 0170c89

File tree

1 file changed

+16
-43
lines changed

1 file changed

+16
-43
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,25 +2017,21 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
20172017
if (!isUnresolvedOrTypeVarType(fnType) &&
20182018
!fnType->is<AnyFunctionType>() && !fnType->is<MetatypeType>()) {
20192019
auto arg = callExpr->getArg();
2020-
auto isDynamicCallable =
2021-
CS.DynamicCallableCache[fnType->getCanonicalType()].isValid();
20222020

2023-
auto hasCallAsFunctionMethods = fnType->isCallableNominalType(CS.DC);
2024-
2025-
// Diagnose specific @dynamicCallable errors.
2026-
if (isDynamicCallable) {
2027-
auto dynamicCallableMethods =
2028-
CS.DynamicCallableCache[fnType->getCanonicalType()];
2029-
2030-
// Diagnose dynamic calls with keywords on @dynamicCallable types that
2031-
// don't define the `withKeywordArguments` method.
2032-
if (auto tuple = dyn_cast<TupleExpr>(arg)) {
2033-
bool hasArgLabel = llvm::any_of(
2034-
tuple->getElementNames(), [](Identifier i) { return !i.empty(); });
2035-
if (hasArgLabel &&
2036-
dynamicCallableMethods.keywordArgumentsMethods.empty()) {
2037-
diagnose(callExpr->getFn()->getStartLoc(),
2038-
diag::missing_dynamic_callable_kwargs_method, fnType);
2021+
// If the argument is a trailing ClosureExpr (i.e. {....}) and it is on
2022+
// the line after the callee, then it's likely the user forgot to
2023+
// write "do" before their brace stmt.
2024+
// Note that line differences of more than 1 are diagnosed during parsing.
2025+
if (auto *PE = dyn_cast<ParenExpr>(arg)) {
2026+
if (PE->hasTrailingClosure() && isa<ClosureExpr>(PE->getSubExpr())) {
2027+
auto *closure = cast<ClosureExpr>(PE->getSubExpr());
2028+
auto &SM = CS.getASTContext().SourceMgr;
2029+
if (closure->hasAnonymousClosureVars() &&
2030+
closure->getParameters()->size() == 0 &&
2031+
1 + SM.getLineNumber(callExpr->getFn()->getEndLoc()) ==
2032+
SM.getLineNumber(closure->getStartLoc())) {
2033+
diagnose(closure->getStartLoc(), diag::brace_stmt_suggest_do)
2034+
.fixItInsert(closure->getStartLoc(), "do ");
20392035
return true;
20402036
}
20412037
}
@@ -2046,7 +2042,8 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
20462042
auto diag = diagnose(arg->getStartLoc(),
20472043
diag::missing_init_on_metatype_initialization);
20482044
diag.highlight(fnExpr->getSourceRange());
2049-
} else if (!isDynamicCallable) {
2045+
return true;
2046+
} else {
20502047
auto diag = diagnose(arg->getStartLoc(),
20512048
diag::cannot_call_non_function_value, fnType);
20522049
diag.highlight(fnExpr->getSourceRange());
@@ -2059,30 +2056,6 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
20592056
diag.fixItRemove(arg->getSourceRange());
20602057
}
20612058
}
2062-
}
2063-
2064-
// If the argument is a trailing ClosureExpr (i.e. {....}) and it is on
2065-
// the line after the callee, then it's likely the user forgot to
2066-
// write "do" before their brace stmt.
2067-
// Note that line differences of more than 1 are diagnosed during parsing.
2068-
if (auto *PE = dyn_cast<ParenExpr>(arg)) {
2069-
if (PE->hasTrailingClosure() && isa<ClosureExpr>(PE->getSubExpr())) {
2070-
auto *closure = cast<ClosureExpr>(PE->getSubExpr());
2071-
auto &SM = CS.getASTContext().SourceMgr;
2072-
if (closure->hasAnonymousClosureVars() &&
2073-
closure->getParameters()->size() == 0 &&
2074-
1 + SM.getLineNumber(callExpr->getFn()->getEndLoc()) ==
2075-
SM.getLineNumber(closure->getStartLoc())) {
2076-
diagnose(closure->getStartLoc(), diag::brace_stmt_suggest_do)
2077-
.fixItInsert(closure->getStartLoc(), "do ");
2078-
}
2079-
}
2080-
}
2081-
2082-
// Use the existing machinery to provide more useful diagnostics for
2083-
// @dynamicCallable calls, rather than cannot_call_non_function_value.
2084-
if ((isExistentialMetatypeType || !isDynamicCallable) &&
2085-
!hasCallAsFunctionMethods) {
20862059
return true;
20872060
}
20882061
}

0 commit comments

Comments
 (0)