@@ -2287,12 +2287,14 @@ Constraint *ConstraintSystem::selectDisjunction() {
22872287 auto cs = this ;
22882288 auto minDisjunction = std::min_element (disjunctions.begin (), disjunctions.end (),
22892289 [&](Constraint *first, Constraint *second) -> bool {
2290+ unsigned firstActive = first->countActiveNestedConstraints ();
2291+ unsigned secondActive = second->countActiveNestedConstraints ();
22902292 unsigned firstFavored = first->countFavoredNestedConstraints ();
22912293 unsigned secondFavored = second->countFavoredNestedConstraints ();
22922294
22932295 if (!isOperatorBindOverload (first->getNestedConstraints ().front ()) ||
22942296 !isOperatorBindOverload (second->getNestedConstraints ().front ()))
2295- return first-> countActiveNestedConstraints () < second-> countActiveNestedConstraints () ;
2297+ return firstActive < secondActive ;
22962298
22972299 if (firstFavored == secondFavored) {
22982300 // Look for additional choices that are "favored"
@@ -2305,17 +2307,19 @@ Constraint *ConstraintSystem::selectDisjunction() {
23052307 secondFavored += secondExisting.size ();
23062308 }
23072309
2308- firstFavored = firstFavored ? firstFavored : first->countActiveNestedConstraints ();
2309- secondFavored = secondFavored ? secondFavored : second->countActiveNestedConstraints ();
2310-
23112310 // Everything else equal, choose the disjunction with the greatest
23122311 // number of resoved argument types. The number of resolved argument
23132312 // types is always zero for disjunctions that don't represent applied
23142313 // overloads.
23152314 if (firstFavored == secondFavored) {
2316- return first->countResolvedArgumentTypes (*this ) > second->countResolvedArgumentTypes (*this );
2315+ if (firstActive != secondActive)
2316+ return firstActive < secondActive;
2317+
2318+ return (first->countResolvedArgumentTypes (*this ) > second->countResolvedArgumentTypes (*this ));
23172319 }
23182320
2321+ firstFavored = firstFavored ? firstFavored : firstActive;
2322+ secondFavored = secondFavored ? secondFavored : secondActive;
23192323 return firstFavored < secondFavored;
23202324 });
23212325
0 commit comments