@@ -653,6 +653,9 @@ static bool collectPossibleCalleesForApply(
653653 } else if (auto CRCE = dyn_cast<ConstructorRefCallExpr>(fnExpr)) {
654654 collectPossibleCalleesByQualifiedLookup (
655655 DC, CRCE->getArg (), DeclNameRef::createConstructor (), candidates);
656+ } else if (auto TE = dyn_cast<TypeExpr>(fnExpr)) {
657+ collectPossibleCalleesByQualifiedLookup (
658+ DC, TE, DeclNameRef::createConstructor (), candidates);
656659 } else if (auto *UME = dyn_cast<UnresolvedMemberExpr>(fnExpr)) {
657660 collectPossibleCalleesForUnresolvedMember (DC, UME, candidates);
658661 }
@@ -806,23 +809,37 @@ static bool getPositionInParams(DeclContext &DC, Expr *Args, Expr *CCExpr,
806809 }
807810
808811 // Look for a matching parameter label.
809- bool FoundLabelMatch = false ;
812+ bool AdvancedPosInParams = false ;
810813 for (unsigned i = PosInParams; i < Params.size (); ++i) {
811814 if (Params[i].getLabel () == ArgName) {
812815 // We have found a label match. Advance the position in the params
813816 // to point to the param after the one with this label.
814817 PosInParams = i + 1 ;
815- FoundLabelMatch = true ;
818+ AdvancedPosInParams = true ;
816819 if (Params[i].isVariadic ()) {
817820 LastParamWasVariadic = true ;
818821 }
819822 break ;
820823 }
821824 }
822825
823- if (!FoundLabelMatch) {
824- // We haven't found a matching argument label. Assume the current one is
825- // named incorrectly and advance by one.
826+ bool IsTrailingClosure =
827+ PosInArgs >= tuple->getNumElements () - tuple->getNumTrailingElements ();
828+ if (!AdvancedPosInParams && IsTrailingClosure) {
829+ // If the argument is a trailing closure, it can't match non-function
830+ // parameters. Advance to the next function parameter.
831+ for (unsigned i = PosInParams; i < Params.size (); ++i) {
832+ if (Params[i].getParameterType ()->is <FunctionType>()) {
833+ PosInParams = i + 1 ;
834+ AdvancedPosInParams = true ;
835+ break ;
836+ }
837+ }
838+ }
839+
840+ if (!AdvancedPosInParams) {
841+ // We haven't performed any special advance logic. Assume the argument
842+ // and parameter match, so advance PosInParams by 1.
826843 ++PosInParams;
827844 }
828845 }
0 commit comments