@@ -3044,116 +3044,6 @@ bool FailureDiagnosis::diagnoseImplicitSelfErrors(
30443044 return false ;
30453045}
30463046
3047- static bool diagnoseTupleParameterMismatch (CalleeCandidateInfo &CCI,
3048- ArrayRef<AnyFunctionType::Param> params,
3049- ArrayRef<AnyFunctionType::Param> args,
3050- Expr *fnExpr, Expr *argExpr,
3051- bool isTopLevel = true ) {
3052- // Try to diagnose function call tuple parameter splat only if
3053- // there is no trailing or argument closure, because
3054- // FailureDiagnosis::visitClosureExpr will produce better
3055- // diagnostic and fix-it for trailing closure case.
3056- if (isTopLevel) {
3057- if (CCI.hasTrailingClosure )
3058- return false ;
3059-
3060- if (auto *parenExpr = dyn_cast<ParenExpr>(argExpr)) {
3061- if (isa<ClosureExpr>(parenExpr->getSubExpr ()))
3062- return false ;
3063- }
3064- }
3065-
3066- if (params.size () == 1 && args.size () == 1 ) {
3067- auto paramType = params.front ().getOldType ();
3068- auto argType = args.front ().getOldType ();
3069-
3070- if (auto *paramFnType = paramType->getAs <AnyFunctionType>()) {
3071- // Only if both of the parameter and argument types are functions
3072- // let's recur into diagnosing their arguments.
3073- if (auto *argFnType = argType->getAs <AnyFunctionType>())
3074- return diagnoseTupleParameterMismatch (CCI, paramFnType->getParams (),
3075- argFnType->getParams (), fnExpr,
3076- argExpr, /* isTopLevel */ false );
3077- return false ;
3078- }
3079- }
3080-
3081- if (params.size () != 1 || args.empty ())
3082- return false ;
3083-
3084- auto paramType = params.front ().getOldType ();
3085-
3086- if (args.size () == 1 ) {
3087- auto argType = args.front ().getOldType ();
3088- if (auto *paramFnType = paramType->getAs <AnyFunctionType>()) {
3089- // Only if both of the parameter and argument types are functions
3090- // let's recur into diagnosing their arguments.
3091- if (auto *argFnType = argType->getAs <AnyFunctionType>())
3092- return diagnoseTupleParameterMismatch (CCI, paramFnType->getParams (),
3093- argFnType->getParams (), fnExpr,
3094- argExpr, /* isTopLevel */ false );
3095- }
3096-
3097- return false ;
3098- }
3099-
3100- // Let's see if inferred argument is actually a tuple inside of Paren.
3101- auto *paramTupleTy = paramType->getAs <TupleType>();
3102- if (!paramTupleTy)
3103- return false ;
3104-
3105- if (paramTupleTy->getNumElements () != args.size ())
3106- return false ;
3107-
3108- // Looks like the number of tuple elements matches number
3109- // of function arguments, which means we can we can emit an
3110- // error about an attempt to make use of tuple splat or tuple
3111- // destructuring, unfortunately we can't provide a fix-it for
3112- // this case.
3113- auto &TC = CCI.CS .TC ;
3114- if (isTopLevel) {
3115- if (auto *decl = CCI[0 ].getDecl ()) {
3116- Identifier name;
3117- auto kind = decl->getDescriptiveKind ();
3118- // Constructors/descructors and subscripts don't really have names.
3119- if (!(isa<ConstructorDecl>(decl) || isa<DestructorDecl>(decl) ||
3120- isa<SubscriptDecl>(decl))) {
3121- name = decl->getBaseName ().getIdentifier ();
3122- }
3123-
3124- TC.diagnose (argExpr->getLoc (), diag::single_tuple_parameter_mismatch,
3125- kind, name, paramTupleTy, !name.empty ())
3126- .highlight (argExpr->getSourceRange ())
3127- .fixItInsertAfter (argExpr->getStartLoc (), " (" )
3128- .fixItInsert (argExpr->getEndLoc (), " )" );
3129- } else {
3130- TC.diagnose (argExpr->getLoc (),
3131- diag::unknown_single_tuple_parameter_mismatch, paramTupleTy)
3132- .highlight (argExpr->getSourceRange ())
3133- .fixItInsertAfter (argExpr->getStartLoc (), " (" )
3134- .fixItInsert (argExpr->getEndLoc (), " )" );
3135- }
3136- } else {
3137- TC.diagnose (argExpr->getLoc (),
3138- diag::nested_tuple_parameter_destructuring, paramTupleTy,
3139- CCI.CS .getType (fnExpr));
3140- }
3141-
3142- return true ;
3143- }
3144-
3145- static bool diagnoseTupleParameterMismatch (CalleeCandidateInfo &CCI,
3146- ArrayRef<FunctionType::Param> params,
3147- Type argType, Expr *fnExpr,
3148- Expr *argExpr,
3149- bool isTopLevel = true ) {
3150- llvm::SmallVector<AnyFunctionType::Param, 4 > args;
3151- FunctionType::decomposeInput (argType, args);
3152-
3153- return diagnoseTupleParameterMismatch (CCI, params, args, fnExpr, argExpr,
3154- isTopLevel);
3155- }
3156-
31573047class ArgumentMatcher : public MatchCallArgumentListener {
31583048 TypeChecker &TC;
31593049 Expr *FnExpr;
@@ -3469,10 +3359,6 @@ diagnoseSingleCandidateFailures(CalleeCandidateInfo &CCI, Expr *fnExpr,
34693359 }
34703360 }
34713361
3472- if (diagnoseTupleParameterMismatch (CCI, candidate.getParameters (),
3473- CCI.CS .getType (argExpr), fnExpr, argExpr))
3474- return true ;
3475-
34763362 // We only handle structural errors here.
34773363 if (CCI.closeness != CC_ArgumentLabelMismatch &&
34783364 CCI.closeness != CC_ArgumentCountMismatch)
0 commit comments