@@ -1490,55 +1490,39 @@ void ConstraintSystem::addOverloadSet(Type boundType,
1490
1490
return ;
1491
1491
}
1492
1492
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
+
1493
1504
SmallVector<Constraint *, 4 > overloads;
1494
-
1495
1505
// As we do for other favored constraints, if a favored overload has been
1496
1506
// specified, let it be the first term in the disjunction.
1497
1507
if (favoredChoice) {
1498
- auto bindOverloadConstraint =
1499
- Constraint::createBindOverload (*this ,
1500
- boundType,
1501
- *favoredChoice,
1502
- useDC,
1503
- locator);
1504
-
1505
1508
assert ((!favoredChoice->isDecl () ||
1506
1509
!favoredChoice->getDecl ()->getAttrs ().isUnavailable (
1507
1510
getASTContext ())) &&
1508
1511
" Cannot make unavailable decl favored!" );
1509
- bindOverloadConstraint->setFavored ();
1510
-
1511
- overloads.push_back (bindOverloadConstraint);
1512
+ recordChoice (overloads, *favoredChoice, /* isFavored=*/ true );
1512
1513
}
1513
-
1514
+
1514
1515
for (auto &choice : choices) {
1515
1516
if (favoredChoice && (favoredChoice == &choice))
1516
1517
continue ;
1517
-
1518
- overloads.push_back (Constraint::createBindOverload (*this , boundType, choice,
1519
- useDC, locator));
1520
- }
1521
1518
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);
1530
1520
}
1531
1521
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);
1540
1524
1541
- addDisjunctionConstraint (outerConstraints , locator, ForgetChoice, favoredChoice );
1525
+ addDisjunctionConstraint (overloads , locator, ForgetChoice);
1542
1526
}
1543
1527
1544
1528
// / If we're resolving an overload set with a decl that has special type
0 commit comments