@@ -970,8 +970,6 @@ static void determineBestChoicesInContext(
970
970
971
971
bool hasArgumentCandidates = false ;
972
972
bool isOperator = isOperatorDisjunction(disjunction);
973
- bool isNilCoalescingOperator =
974
- isOperator && isOperatorNamed(disjunction, " ??" );
975
973
976
974
for (unsigned i = 0 , n = argFuncType->getNumParams (); i != n; ++i) {
977
975
const auto ¶m = argFuncType->getParams ()[i];
@@ -1341,17 +1339,26 @@ static void determineBestChoicesInContext(
1341
1339
paramType = paramType->lookThroughAllOptionalTypes (paramOptionals);
1342
1340
1343
1341
if (!candidateOptionals.empty () || !paramOptionals.empty ()) {
1342
+ auto requiresOptionalInjection = [&]() {
1343
+ return paramOptionals.size () > candidateOptionals.size ();
1344
+ };
1345
+
1344
1346
// Can match i.e. Int? to Int or T to Int?
1345
1347
if ((paramOptionals.empty () &&
1346
1348
paramType->is <GenericTypeParamType>()) ||
1347
1349
paramOptionals.size () >= candidateOptionals.size ()) {
1348
1350
auto score = scoreCandidateMatch (genericSig, choice, candidateType,
1349
1351
paramType, options);
1350
- // Injection lowers the score slightly to comply with
1351
- // old behavior where exact matches on operator parameter
1352
- // types were always preferred.
1353
- return score > 0 && choice->isOperator () ? score.value () - 0.1
1354
- : score;
1352
+
1353
+ if (score > 0 ) {
1354
+ // Injection lowers the score slightly to comply with
1355
+ // old behavior where exact matches on operator parameter
1356
+ // types were always preferred.
1357
+ if (choice->isOperator () && requiresOptionalInjection ())
1358
+ return score.value () - 0.1 ;
1359
+ }
1360
+
1361
+ return score;
1355
1362
}
1356
1363
1357
1364
// Optionality mismatch.
@@ -1605,20 +1612,6 @@ static void determineBestChoicesInContext(
1605
1612
double bestCandidateScore = 0 ;
1606
1613
llvm::BitVector mismatches (argumentCandidates[argIdx].size ());
1607
1614
1608
- // `??` is overloaded on optionality of the second parameter,
1609
- // prevent ranking the argument candidates for this parameter
1610
- // if there are candidates that come from failable initializer
1611
- // overloads because non-optional candidates are always going
1612
- // to be better and that can skew the selection.
1613
- if (isNilCoalescingOperator && argIdx == 1 ) {
1614
- if (llvm::any_of (argumentCandidates[argIdx],
1615
- [](const auto &candidate) {
1616
- return candidate.fromInitializerCall &&
1617
- candidate.type ->getOptionalObjectType ();
1618
- }))
1619
- continue ;
1620
- }
1621
-
1622
1615
for (unsigned candidateIdx :
1623
1616
indices (argumentCandidates[argIdx])) {
1624
1617
// If one of the candidates matched exactly there is no reason
0 commit comments