@@ -2017,25 +2017,21 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
2017
2017
if (!isUnresolvedOrTypeVarType (fnType) &&
2018
2018
!fnType->is <AnyFunctionType>() && !fnType->is <MetatypeType>()) {
2019
2019
auto arg = callExpr->getArg ();
2020
- auto isDynamicCallable =
2021
- CS.DynamicCallableCache [fnType->getCanonicalType ()].isValid ();
2022
2020
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 " );
2039
2035
return true ;
2040
2036
}
2041
2037
}
@@ -2046,7 +2042,8 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
2046
2042
auto diag = diagnose (arg->getStartLoc (),
2047
2043
diag::missing_init_on_metatype_initialization);
2048
2044
diag.highlight (fnExpr->getSourceRange ());
2049
- } else if (!isDynamicCallable) {
2045
+ return true ;
2046
+ } else {
2050
2047
auto diag = diagnose (arg->getStartLoc (),
2051
2048
diag::cannot_call_non_function_value, fnType);
2052
2049
diag.highlight (fnExpr->getSourceRange ());
@@ -2059,30 +2056,6 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
2059
2056
diag.fixItRemove (arg->getSourceRange ());
2060
2057
}
2061
2058
}
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) {
2086
2059
return true ;
2087
2060
}
2088
2061
}
0 commit comments