|
2 | 2 | //
|
3 | 3 | // This source file is part of the Swift.org open source project
|
4 | 4 | //
|
5 |
| -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors |
| 5 | +// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors |
6 | 6 | // Licensed under Apache License v2.0 with Runtime Library Exception
|
7 | 7 | //
|
8 | 8 | // See https://swift.org/LICENSE.txt for license information
|
@@ -527,10 +527,11 @@ static void determineBestChoicesInContext(
|
527 | 527 | // type matches a parameter type (i.e. when partially resolved generic
|
528 | 528 | // types are matched) this function is going to produce \c std::nullopt
|
529 | 529 | // instead of `0` that indicates "not a match".
|
530 |
| - std::function<std::optional<double>(GenericSignature, Type, Type, |
531 |
| - MatchOptions)> |
| 530 | + std::function<std::optional<double>(GenericSignature, ValueDecl *, Type, |
| 531 | + Type, MatchOptions)> |
532 | 532 | scoreCandidateMatch =
|
533 |
| - [&](GenericSignature genericSig, Type candidateType, Type paramType, |
| 533 | + [&](GenericSignature genericSig, ValueDecl *choice, |
| 534 | + Type candidateType, Type paramType, |
534 | 535 | MatchOptions options) -> std::optional<double> {
|
535 | 536 | auto areEqual = [&](Type a, Type b) {
|
536 | 537 | return a->getDesugaredType()->isEqual(b->getDesugaredType());
|
@@ -618,13 +619,12 @@ static void determineBestChoicesInContext(
|
618 | 619 |
|
619 | 620 | if (!candidateOptionals.empty() || !paramOptionals.empty()) {
|
620 | 621 | if (paramOptionals.size() >= candidateOptionals.size()) {
|
621 |
| - auto score = scoreCandidateMatch(genericSig, candidateType, |
| 622 | + auto score = scoreCandidateMatch(genericSig, choice, candidateType, |
622 | 623 | paramType, options);
|
623 | 624 | // Injection lowers the score slightly to comply with
|
624 | 625 | // old behavior where exact matches on operator parameter
|
625 | 626 | // types were always preferred.
|
626 |
| - return score == 1 && isOperatorDisjunction(disjunction) ? 0.9 |
627 |
| - : score; |
| 627 | + return score == 1 && choice->isOperator() ? 0.9 : score; |
628 | 628 | }
|
629 | 629 |
|
630 | 630 | // Optionality mismatch.
|
@@ -746,7 +746,7 @@ static void determineBestChoicesInContext(
|
746 | 746 | // everything else the solver should try both concrete and
|
747 | 747 | // generic and disambiguate during ranking.
|
748 | 748 | if (result == CheckRequirementsResult::Success)
|
749 |
| - return isOperatorDisjunction(disjunction) ? 0.9 : 1.0; |
| 749 | + return choice->isOperator() ? 0.9 : 1.0; |
750 | 750 |
|
751 | 751 | return 0;
|
752 | 752 | }
|
@@ -914,7 +914,7 @@ static void determineBestChoicesInContext(
|
914 | 914 | options |= MatchFlag::DisableCGFloatDoubleConversion;
|
915 | 915 |
|
916 | 916 | auto candidateScore = scoreCandidateMatch(
|
917 |
| - genericSig, candidateType, paramType, options); |
| 917 | + genericSig, decl, candidateType, paramType, options); |
918 | 918 |
|
919 | 919 | if (!candidateScore)
|
920 | 920 | continue;
|
@@ -984,7 +984,7 @@ static void determineBestChoicesInContext(
|
984 | 984 | ->isCGFloat())
|
985 | 985 | return false;
|
986 | 986 |
|
987 |
| - return scoreCandidateMatch(genericSig, |
| 987 | + return scoreCandidateMatch(genericSig, decl, |
988 | 988 | overloadType->getResult(),
|
989 | 989 | candidateResultTy,
|
990 | 990 | /*options=*/{}) > 0;
|
|
0 commit comments