@@ -1490,55 +1490,39 @@ void ConstraintSystem::addOverloadSet(Type boundType,
14901490 return ;
14911491 }
14921492
1493+ auto recordChoice = [&](SmallVectorImpl<Constraint *> &choices,
1494+ const OverloadChoice &choice,
1495+ bool isFavored = false ) {
1496+ auto *constraint = Constraint::createBindOverload (*this , boundType, choice,
1497+ useDC, locator);
1498+ if (isFavored)
1499+ constraint->setFavored ();
1500+
1501+ choices.push_back (constraint);
1502+ };
1503+
14931504 SmallVector<Constraint *, 4 > overloads;
1494-
14951505 // As we do for other favored constraints, if a favored overload has been
14961506 // specified, let it be the first term in the disjunction.
14971507 if (favoredChoice) {
1498- auto bindOverloadConstraint =
1499- Constraint::createBindOverload (*this ,
1500- boundType,
1501- *favoredChoice,
1502- useDC,
1503- locator);
1504-
15051508 assert ((!favoredChoice->isDecl () ||
15061509 !favoredChoice->getDecl ()->getAttrs ().isUnavailable (
15071510 getASTContext ())) &&
15081511 " Cannot make unavailable decl favored!" );
1509- bindOverloadConstraint->setFavored ();
1510-
1511- overloads.push_back (bindOverloadConstraint);
1512+ recordChoice (overloads, *favoredChoice, /* isFavored=*/ true );
15121513 }
1513-
1514+
15141515 for (auto &choice : choices) {
15151516 if (favoredChoice && (favoredChoice == &choice))
15161517 continue ;
1517-
1518- overloads.push_back (Constraint::createBindOverload (*this , boundType, choice,
1519- useDC, locator));
1520- }
15211518
1522- auto innerDisjunction = Constraint::createDisjunction (*this , overloads,
1523- locator, ForgetChoice);
1524- if (outerAlternatives.empty ()) {
1525- if (favoredChoice)
1526- innerDisjunction->setFavored ();
1527-
1528- addUnsolvedConstraint (innerDisjunction);
1529- return ;
1519+ recordChoice (overloads, choice);
15301520 }
15311521
1532- SmallVector<Constraint *, 4 > outerConstraints;
1533- outerConstraints.push_back (innerDisjunction);
1534- innerDisjunction->setFavored ();
1535- for (auto choice : outerAlternatives) {
1536- outerConstraints.push_back (Constraint::createBindOverload (
1537- *this , boundType, choice,
1538- useDC, locator));
1539- }
1522+ for (auto &choice : outerAlternatives)
1523+ recordChoice (overloads, choice);
15401524
1541- addDisjunctionConstraint (outerConstraints , locator, ForgetChoice, favoredChoice );
1525+ addDisjunctionConstraint (overloads , locator, ForgetChoice);
15421526}
15431527
15441528// / If we're resolving an overload set with a decl that has special type
0 commit comments