@@ -431,24 +431,24 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
431
431
432
432
// If we have a trailing closure, it maps to the last parameter.
433
433
if (hasTrailingClosure && numParams > 0 ) {
434
+ unsigned lastParamIdx = numParams - 1 ;
435
+ bool lastAcceptsTrailingClosure =
436
+ acceptsTrailingClosure (params[lastParamIdx]);
437
+
434
438
// If the last parameter is defaulted, this might be
435
439
// an attempt to use a trailing closure with previous
436
440
// parameter that accepts a function type e.g.
437
441
//
438
442
// func foo(_: () -> Int, _ x: Int = 0) {}
439
443
// foo { 42 }
440
- bool lastAcceptsTrailingClosure = false ;
441
- unsigned lastParamIdx = numParams - 1 ;
442
- for ( unsigned i : indices ( params)) {
443
- unsigned idx = numParams - 1 - i;
444
- if (acceptsTrailingClosure (params[idx] )) {
444
+ if (! lastAcceptsTrailingClosure && numParams > 1 &&
445
+ paramInfo. hasDefaultArgument (lastParamIdx)) {
446
+ auto paramType = params[lastParamIdx - 1 ]. getPlainType ();
447
+ // If the parameter before defaulted last accepts.
448
+ if (paramType-> is <AnyFunctionType>( )) {
445
449
lastAcceptsTrailingClosure = true ;
446
- lastParamIdx = idx;
447
- break ;
450
+ lastParamIdx -= 1 ;
448
451
}
449
- if (paramInfo.hasDefaultArgument (idx))
450
- continue ;
451
- break ;
452
452
}
453
453
454
454
bool isExtraClosure = false ;
0 commit comments