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