@@ -649,6 +649,7 @@ class DisjunctionStep final : public BindingStep<DisjunctionChoiceProducer> {
649
649
: BindingStep(cs, {cs, disjunction}, solutions), Disjunction(disjunction),
650
650
AfterDisjunction (erase(disjunction)) {
651
651
assert (Disjunction->getKind () == ConstraintKind::Disjunction);
652
+ pruneOverloadSet (Disjunction);
652
653
++cs.solverState ->NumDisjunctions ;
653
654
}
654
655
@@ -696,6 +697,43 @@ class DisjunctionStep final : public BindingStep<DisjunctionChoiceProducer> {
696
697
// / simplified further, false otherwise.
697
698
bool attempt (const DisjunctionChoice &choice) override ;
698
699
700
+ // Check if selected disjunction has a representative
701
+ // this might happen when there are multiple binary operators
702
+ // chained together. If so, disable choices which differ
703
+ // from currently selected representative.
704
+ void pruneOverloadSet (Constraint *disjunction) {
705
+ auto *choice = disjunction->getNestedConstraints ().front ();
706
+ auto *typeVar = choice->getFirstType ()->getAs <TypeVariableType>();
707
+ if (!typeVar)
708
+ return ;
709
+
710
+ auto *repr = typeVar->getImpl ().getRepresentative (nullptr );
711
+ if (!repr || repr == typeVar)
712
+ return ;
713
+
714
+ for (auto *resolved = getResolvedOverloads (); resolved;
715
+ resolved = resolved->Previous ) {
716
+ if (!resolved->BoundType ->isEqual (repr))
717
+ continue ;
718
+
719
+ auto &representative = resolved->Choice ;
720
+ if (!representative.isDecl ())
721
+ return ;
722
+
723
+ // Disable all of the overload choices which are different from
724
+ // the one which is currently picked for representative.
725
+ for (auto *constraint : disjunction->getNestedConstraints ()) {
726
+ auto choice = constraint->getOverloadChoice ();
727
+ if (!choice.isDecl () || choice.getDecl () == representative.getDecl ())
728
+ continue ;
729
+
730
+ constraint->setDisabled ();
731
+ DisabledChoices.push_back (constraint);
732
+ }
733
+ break ;
734
+ }
735
+ };
736
+
699
737
// Figure out which of the solutions has the smallest score.
700
738
static Optional<Score> getBestScore (SmallVectorImpl<Solution> &solutions) {
701
739
assert (!solutions.empty ());
0 commit comments