@@ -200,6 +200,15 @@ static ConstraintSystem::TypeMatchOptions getDefaultDecompositionOptions(
200
200
return flags | ConstraintSystem::TMF_GenerateConstraints;
201
201
}
202
202
203
+ // / Whether the given parameter requires an argument.
204
+ static bool parameterRequiresArgument (
205
+ ArrayRef<AnyFunctionType::Param> params,
206
+ const ParameterListInfo ¶mInfo,
207
+ unsigned paramIdx) {
208
+ return !paramInfo.hasDefaultArgument (paramIdx)
209
+ && !params[paramIdx].isVariadic ();
210
+ }
211
+
203
212
// / Determine whether any parameter from the given index up until the end
204
213
// / requires an argument to be provided.
205
214
// /
@@ -222,8 +231,7 @@ static bool anyParameterRequiresArgument(
222
231
break ;
223
232
224
233
// If this parameter requires an argument, tell the caller.
225
- if (!paramInfo.hasDefaultArgument (paramIdx)
226
- && !params[paramIdx].isVariadic ())
234
+ if (parameterRequiresArgument (params, paramInfo, paramIdx))
227
235
return true ;
228
236
}
229
237
@@ -316,13 +324,6 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
316
324
if (numClaimedArgs == numArgs)
317
325
return None;
318
326
319
- // If we're claiming variadic arguments, do not claim an unlabeled trailing
320
- // closure argument.
321
- if (forVariadic &&
322
- unlabeledTrailingClosureArgIndex &&
323
- nextArgIdx == *unlabeledTrailingClosureArgIndex)
324
- return None;
325
-
326
327
// Go hunting for an unclaimed argument whose name does match.
327
328
Optional<unsigned > claimedWithSameName;
328
329
for (unsigned i = nextArgIdx; i != numArgs; ++i) {
@@ -425,10 +426,10 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
425
426
return ;
426
427
}
427
428
428
- // If this parameter has a default argument, consider applying a "fuzzy"
429
- // match rule that skips this parameter if doing so is the only way to
430
- // satisfy
431
- if (paramInfo. hasDefaultArgument ( paramIdx) &&
429
+ // If this parameter does not require an argument, consider applying a
430
+ // "fuzzy" match rule that skips this parameter if doing so is the only
431
+ // way to successfully match arguments to parameters.
432
+ if (! parameterRequiresArgument (params, paramInfo, paramIdx) &&
432
433
param.getPlainType ()->getASTContext ().LangOpts
433
434
.EnableFuzzyForwardScanTrailingClosureMatching &&
434
435
anyParameterRequiresArgument (
@@ -469,10 +470,21 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
469
470
auto currentNextArgIdx = nextArgIdx;
470
471
{
471
472
nextArgIdx = *claimed;
473
+
472
474
// Claim any additional unnamed arguments.
473
- while (
474
- (claimed = claimNextNamed (nextArgIdx, Identifier (), false , true ))) {
475
- parameterBindings[paramIdx].push_back (*claimed);
475
+ while (true ) {
476
+ // If the next argument is the unlabeled trailing closure and the
477
+ // variadic parameter does not accept the unlabeled trailing closure
478
+ // argument, we're done.
479
+ if (unlabeledTrailingClosureArgIndex &&
480
+ skipClaimedArgs (nextArgIdx) == *unlabeledTrailingClosureArgIndex &&
481
+ !paramInfo.acceptsUnlabeledTrailingClosureArgument (paramIdx))
482
+ break ;
483
+
484
+ if ((claimed = claimNextNamed (nextArgIdx, Identifier (), false , true )))
485
+ parameterBindings[paramIdx].push_back (*claimed);
486
+ else
487
+ break ;
476
488
}
477
489
}
478
490
0 commit comments