@@ -100,7 +100,7 @@ static bool isOverloadedDeclRef(Constraint *disjunction) {
100
100
101
101
// / Given a set of disjunctions, attempt to determine
102
102
// / favored choices in the current context.
103
- static void determineBestChoicesInContext (
103
+ static Constraint * determineBestChoicesInContext (
104
104
ConstraintSystem &cs, SmallVectorImpl<Constraint *> &disjunctions,
105
105
llvm::DenseMap<Constraint *, llvm::TinyPtrVector<Constraint *>>
106
106
&favorings) {
@@ -122,7 +122,7 @@ static void determineBestChoicesInContext(
122
122
123
123
auto argumentList = cs.getArgumentList (applicableFn.get ()->getLocator ());
124
124
if (!argumentList || cs.containsIDEInspectionTarget (argumentList))
125
- return ;
125
+ return nullptr ;
126
126
127
127
SmallVector<FunctionType::Param, 8 > argsWithLabels;
128
128
{
@@ -623,6 +623,22 @@ static void determineBestChoicesInContext(
623
623
for (auto *choice : favoredChoicesPerDisjunction[entry.first ])
624
624
favorings[entry.first ].push_back (choice);
625
625
}
626
+
627
+ if (bestOverallScore == 0 )
628
+ return nullptr ;
629
+
630
+ Constraint *bestDisjunction = nullptr ;
631
+ for (auto *disjunction : disjunctions) {
632
+ if (disjunctionScores[disjunction] != bestOverallScore)
633
+ continue ;
634
+
635
+ if (!bestDisjunction)
636
+ bestDisjunction = disjunction;
637
+ else // Multiple disjunctions with the same score.
638
+ return nullptr ;
639
+ }
640
+
641
+ return bestDisjunction;
626
642
}
627
643
628
644
// Attempt to find a disjunction of bind constraints where all options
@@ -695,7 +711,9 @@ ConstraintSystem::selectDisjunction() {
695
711
return std::make_pair (disjunction, llvm::TinyPtrVector<Constraint *>());
696
712
697
713
llvm::DenseMap<Constraint *, llvm::TinyPtrVector<Constraint *>> favorings;
698
- determineBestChoicesInContext (*this , disjunctions, favorings);
714
+ if (auto *bestDisjunction =
715
+ determineBestChoicesInContext (*this , disjunctions, favorings))
716
+ return std::make_pair (bestDisjunction, favorings[bestDisjunction]);
699
717
700
718
// Pick the disjunction with the smallest number of favored, then active
701
719
// choices.
0 commit comments