@@ -430,24 +430,24 @@ matchCallArguments(SmallVectorImpl<AnyFunctionType::Param> &args,
430430
431431 // If we have a trailing closure, it maps to the last parameter.
432432 if (hasTrailingClosure && numParams > 0 ) {
433- unsigned lastParamIdx = numParams - 1 ;
434- bool lastAcceptsTrailingClosure =
435- acceptsTrailingClosure (params[lastParamIdx]);
436-
437433 // If the last parameter is defaulted, this might be
438434 // an attempt to use a trailing closure with previous
439435 // parameter that accepts a function type e.g.
440436 //
441437 // func foo(_: () -> Int, _ x: Int = 0) {}
442438 // 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] )) {
448444 lastAcceptsTrailingClosure = true ;
449- lastParamIdx -= 1 ;
445+ lastParamIdx = idx;
446+ break ;
450447 }
448+ if (paramInfo.hasDefaultArgument (idx))
449+ continue ;
450+ break ;
451451 }
452452
453453 bool isExtraClosure = false ;
0 commit comments