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