@@ -232,7 +232,7 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
232
232
parameterBindings.resize (numParams);
233
233
234
234
// Keep track of which arguments we have claimed from the argument tuple.
235
- unsigned nextArgIdx = 0 , numArgs = args.size ();
235
+ unsigned numArgs = args.size ();
236
236
SmallVector<bool , 4 > claimedArgs (numArgs, false );
237
237
SmallVector<Identifier, 4 > actualArgNames;
238
238
unsigned numClaimedArgs = 0 ;
@@ -278,18 +278,18 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
278
278
};
279
279
280
280
// Local function that skips over any claimed arguments.
281
- auto skipClaimedArgs = [&]() {
281
+ auto skipClaimedArgs = [&](unsigned &nextArgIdx ) {
282
282
while (nextArgIdx != numArgs && claimedArgs[nextArgIdx])
283
283
++nextArgIdx;
284
284
};
285
285
286
286
// Local function that retrieves the next unclaimed argument with the given
287
287
// name (which may be empty). This routine claims the argument.
288
- auto claimNextNamed
289
- = [&](Identifier paramLabel, bool ignoreNameMismatch,
290
- bool forVariadic = false ) -> Optional<unsigned > {
288
+ auto claimNextNamed = [&]( unsigned &nextArgIdx, Identifier paramLabel,
289
+ bool ignoreNameMismatch,
290
+ bool forVariadic = false ) -> Optional<unsigned > {
291
291
// Skip over any claimed arguments.
292
- skipClaimedArgs ();
292
+ skipClaimedArgs (nextArgIdx );
293
293
294
294
// If we've claimed all of the arguments, there's nothing more to do.
295
295
if (numClaimedArgs == numArgs)
@@ -380,13 +380,14 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
380
380
// Local function that attempts to bind the given parameter to arguments in
381
381
// the list.
382
382
bool haveUnfulfilledParams = false ;
383
- auto bindNextParameter = [&](bool ignoreNameMismatch) {
383
+ auto bindNextParameter = [&](unsigned &nextArgIdx, bool ignoreNameMismatch) {
384
384
const auto ¶m = params[paramIdx];
385
385
386
386
// Handle variadic parameters.
387
387
if (param.isVariadic ()) {
388
388
// Claim the next argument with the name of this parameter.
389
- auto claimed = claimNextNamed (param.getLabel (), ignoreNameMismatch);
389
+ auto claimed =
390
+ claimNextNamed (nextArgIdx, param.getLabel (), ignoreNameMismatch);
390
391
391
392
// If there was no such argument, leave the parameter unfulfilled.
392
393
if (!claimed) {
@@ -407,7 +408,8 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
407
408
{
408
409
nextArgIdx = *claimed;
409
410
// Claim any additional unnamed arguments.
410
- while ((claimed = claimNextNamed (Identifier (), false , true ))) {
411
+ while (
412
+ (claimed = claimNextNamed (nextArgIdx, Identifier (), false , true ))) {
411
413
parameterBindings[paramIdx].push_back (*claimed);
412
414
}
413
415
}
@@ -417,7 +419,8 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
417
419
}
418
420
419
421
// Try to claim an argument for this parameter.
420
- if (auto claimed = claimNextNamed (param.getLabel (), ignoreNameMismatch)) {
422
+ if (auto claimed =
423
+ claimNextNamed (nextArgIdx, param.getLabel (), ignoreNameMismatch)) {
421
424
parameterBindings[paramIdx].push_back (*claimed);
422
425
return ;
423
426
}
@@ -480,10 +483,13 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
480
483
parameterBindings[lastParamIdx].push_back (numArgs - 1 );
481
484
}
482
485
483
- // Mark through the parameters, binding them to their arguments.
484
- for (paramIdx = 0 ; paramIdx != numParams; ++paramIdx) {
485
- if (parameterBindings[paramIdx].empty ())
486
- bindNextParameter (false );
486
+ {
487
+ unsigned nextArgIdx = 0 ;
488
+ // Mark through the parameters, binding them to their arguments.
489
+ for (paramIdx = 0 ; paramIdx != numParams; ++paramIdx) {
490
+ if (parameterBindings[paramIdx].empty ())
491
+ bindNextParameter (nextArgIdx, false );
492
+ }
487
493
}
488
494
489
495
// If we have any unclaimed arguments, complain about those.
@@ -560,14 +566,14 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
560
566
// semi-positionally.
561
567
if (numClaimedArgs != numArgs) {
562
568
// Restart at the first argument/parameter.
563
- nextArgIdx = 0 ;
569
+ unsigned nextArgIdx = 0 ;
564
570
haveUnfulfilledParams = false ;
565
571
for (paramIdx = 0 ; paramIdx != numParams; ++paramIdx) {
566
572
// Skip fulfilled parameters.
567
573
if (!parameterBindings[paramIdx].empty ())
568
574
continue ;
569
575
570
- bindNextParameter (true );
576
+ bindNextParameter (nextArgIdx, true );
571
577
}
572
578
}
573
579
0 commit comments