@@ -181,6 +181,15 @@ static OverloadedDeclRefExpr *isOverloadedDeclRef(Constraint *disjunction) {
181181 return nullptr ;
182182}
183183
184+ static unsigned numOverloadChoicesMatchingOnArity (OverloadedDeclRefExpr *ODRE,
185+ ArgumentList *arguments) {
186+ return llvm::count_if (ODRE->getDecls (), [&arguments](auto *choice) {
187+ if (auto *paramList = getParameterList (choice))
188+ return arguments->size () == paramList->size ();
189+ return false ;
190+ });
191+ }
192+
184193// / This maintains an "old hack" behavior where overloads of some
185194// / `OverloadedDeclRef` calls were favored purely based on number of
186195// / argument and (non-defaulted) parameters matching.
@@ -191,11 +200,7 @@ static void findFavoredChoicesBasedOnArity(
191200 if (!ODRE)
192201 return ;
193202
194- if (llvm::count_if (ODRE->getDecls (), [&argumentList](auto *choice) {
195- if (auto *paramList = getParameterList (choice))
196- return argumentList->size () == paramList->size ();
197- return false ;
198- }) > 1 )
203+ if (numOverloadChoicesMatchingOnArity (ODRE, argumentList) > 1 )
199204 return ;
200205
201206 auto isVariadicGenericOverload = [&](ValueDecl *choice) {
@@ -631,7 +636,16 @@ static Constraint *determineBestChoicesInContext(
631636 double bestScore = 0.0 ;
632637 SmallVector<std::pair<Constraint *, double >, 2 > favoredChoices;
633638
634- bool isOverloadedDeclRefDisjunction = isOverloadedDeclRef (disjunction);
639+ // Preserves old behavior where, for unary calls, the solver
640+ // would not consider choices that didn't match on the number
641+ // of parameters (regardless of defaults) and only exact
642+ // matches were favored.
643+ bool preserveFavoringOfUnlabeledUnaryArgument = false ;
644+ if (argumentList->isUnlabeledUnary ()) {
645+ auto ODRE = isOverloadedDeclRef (disjunction);
646+ preserveFavoringOfUnlabeledUnaryArgument =
647+ !ODRE || numOverloadChoicesMatchingOnArity (ODRE, argumentList) < 2 ;
648+ }
635649
636650 forEachDisjunctionChoice (
637651 cs, disjunction,
@@ -654,11 +668,8 @@ static Constraint *determineBestChoicesInContext(
654668 // matches to filter out non-default literal bindings which otherwise
655669 // could cause "over-favoring".
656670 bool favorExactMatchesOnly = onlyLiteralCandidates;
657- // Preserves old behavior where for unary calls to members
658- // the solver would not consider choices that didn't match on
659- // the number of parameters (regardless of defaults) and only
660- // exact matches were favored.
661- if (!isOverloadedDeclRefDisjunction && argumentList->size () == 1 ) {
671+
672+ if (preserveFavoringOfUnlabeledUnaryArgument) {
662673 // Old behavior completely disregarded the fact that some of
663674 // the parameters could be defaulted.
664675 if (overloadType->getNumParams () != 1 )
0 commit comments