@@ -181,6 +181,15 @@ static OverloadedDeclRefExpr *isOverloadedDeclRef(Constraint *disjunction) {
181
181
return nullptr ;
182
182
}
183
183
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
+
184
193
// / This maintains an "old hack" behavior where overloads of some
185
194
// / `OverloadedDeclRef` calls were favored purely based on number of
186
195
// / argument and (non-defaulted) parameters matching.
@@ -191,11 +200,7 @@ static void findFavoredChoicesBasedOnArity(
191
200
if (!ODRE)
192
201
return ;
193
202
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 )
199
204
return ;
200
205
201
206
auto isVariadicGenericOverload = [&](ValueDecl *choice) {
@@ -631,7 +636,16 @@ static Constraint *determineBestChoicesInContext(
631
636
double bestScore = 0.0 ;
632
637
SmallVector<std::pair<Constraint *, double >, 2 > favoredChoices;
633
638
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
+ }
635
649
636
650
forEachDisjunctionChoice (
637
651
cs, disjunction,
@@ -654,11 +668,8 @@ static Constraint *determineBestChoicesInContext(
654
668
// matches to filter out non-default literal bindings which otherwise
655
669
// could cause "over-favoring".
656
670
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) {
662
673
// Old behavior completely disregarded the fact that some of
663
674
// the parameters could be defaulted.
664
675
if (overloadType->getNumParams () != 1 )
0 commit comments