@@ -1504,17 +1504,33 @@ void ConstraintSystem::ArgumentInfoCollector::minimizeLiteralProtocols() {
1504
1504
if (LiteralProtocols.size () <= 1 )
1505
1505
return ;
1506
1506
1507
- llvm::SmallVector<Type, 2 > defaultTypes;
1508
- for (auto *protocol : LiteralProtocols)
1509
- defaultTypes.push_back (CS.TC .getDefaultType (protocol, CS.DC ));
1507
+ llvm::SmallVector<std::pair<ProtocolDecl *, Type>, 2 > candidates;
1508
+ llvm::SmallVector<ProtocolDecl *, 2 > skippedProtocols;
1509
+
1510
+ for (auto *protocol : LiteralProtocols) {
1511
+ if (auto defaultType = CS.TC .getDefaultType (protocol, CS.DC )) {
1512
+ candidates.push_back ({protocol, defaultType});
1513
+ continue ;
1514
+ }
1515
+
1516
+ // Looks like argument expected to conform to something like
1517
+ // `ExpressibleByNilLiteral` which doesn't have a default
1518
+ // type and as a result can't participate in minimalization.
1519
+ skippedProtocols.push_back (protocol);
1520
+ }
1521
+
1522
+ if (candidates.size () <= 1 )
1523
+ return ;
1524
+
1525
+ unsigned result = 0 ;
1526
+ for (unsigned i = 1 , n = candidates.size (); i != n; ++i) {
1527
+ const auto &candidate = candidates[i];
1510
1528
1511
- auto result = 0 ;
1512
- for (unsigned long i = 1 ; i < LiteralProtocols.size (); ++i) {
1513
1529
auto first =
1514
- CS.TC .conformsToProtocol (defaultTypes[i], LiteralProtocols [result],
1530
+ CS.TC .conformsToProtocol (candidate. second , candidates [result]. first ,
1515
1531
CS.DC , ConformanceCheckFlags::InExpression);
1516
1532
auto second =
1517
- CS.TC .conformsToProtocol (defaultTypes [result], LiteralProtocols[i] ,
1533
+ CS.TC .conformsToProtocol (candidates [result]. second , candidate. first ,
1518
1534
CS.DC , ConformanceCheckFlags::InExpression);
1519
1535
if ((first && second) || (!first && !second))
1520
1536
return ;
@@ -1523,9 +1539,9 @@ void ConstraintSystem::ArgumentInfoCollector::minimizeLiteralProtocols() {
1523
1539
result = i;
1524
1540
}
1525
1541
1526
- auto *protocol = LiteralProtocols[result];
1527
1542
LiteralProtocols.clear ();
1528
- LiteralProtocols.insert (protocol);
1543
+ LiteralProtocols.insert (candidates[result].first );
1544
+ LiteralProtocols.insert (skippedProtocols.begin (), skippedProtocols.end ());
1529
1545
}
1530
1546
1531
1547
void ConstraintSystem::ArgumentInfoCollector::dump () const {
0 commit comments