@@ -1469,53 +1469,46 @@ bool TypeChecker::getDefaultGenericArgumentsString(
1469
1469
genericParamText << " <" ;
1470
1470
1471
1471
auto printGenericParamSummary =
1472
- [&](const GenericTypeParamType *genericParamTy) {
1472
+ [&](GenericTypeParamType *genericParamTy) {
1473
1473
const GenericTypeParamDecl *genericParam = genericParamTy->getDecl ();
1474
1474
if (Type result = getPreferredType (genericParam)) {
1475
1475
result.print (genericParamText);
1476
1476
return ;
1477
1477
}
1478
1478
1479
- ArrayRef<ProtocolDecl *> protocols =
1480
- genericParam->getConformingProtocols ();
1479
+ auto contextTy = typeDecl->mapTypeIntoContext (genericParamTy);
1480
+ if (auto archetypeTy = contextTy->getAs <ArchetypeType>()) {
1481
+ SmallVector<Type, 2 > members;
1481
1482
1482
- Type superclass = genericParam->getSuperclass ();
1483
- if (superclass && !superclass->hasError ()) {
1484
- if (protocols.empty ()) {
1485
- superclass.print (genericParamText);
1486
- return ;
1483
+ bool hasExplicitAnyObject = archetypeTy->requiresClass ();
1484
+ if (auto superclass = archetypeTy->getSuperclass ()) {
1485
+ hasExplicitAnyObject = false ;
1486
+ members.push_back (superclass);
1487
1487
}
1488
1488
1489
- genericParamText << " <#" << genericParam->getName () << " : " ;
1490
- superclass.print (genericParamText);
1491
- for (const ProtocolDecl *proto : protocols) {
1492
- if (proto->isSpecificProtocol (KnownProtocolKind::AnyObject))
1493
- continue ;
1494
- genericParamText << " & " << proto->getName ();
1489
+ for (auto proto : archetypeTy->getConformsTo ()) {
1490
+ members.push_back (proto->getDeclaredType ());
1491
+ if (proto->requiresClass ())
1492
+ hasExplicitAnyObject = false ;
1495
1493
}
1496
- genericParamText << " #>" ;
1497
- return ;
1498
- }
1499
1494
1500
- if (protocols.empty ()) {
1501
- genericParamText << Context.Id_Any ;
1502
- return ;
1503
- }
1495
+ if (hasExplicitAnyObject)
1496
+ members.push_back (typeDecl->getASTContext ().getAnyObjectType ());
1497
+
1498
+ auto type = ProtocolCompositionType::get (typeDecl->getASTContext (),
1499
+ members, hasExplicitAnyObject);
1500
+
1501
+ if (type->isObjCExistentialType () || type->isAny ()) {
1502
+ genericParamText << type;
1503
+ return ;
1504
+ }
1504
1505
1505
- if (protocols.size () == 1 &&
1506
- (protocols.front ()->isObjC () ||
1507
- protocols.front ()->isSpecificProtocol (KnownProtocolKind::AnyObject))) {
1508
- genericParamText << protocols.front ()->getName ();
1506
+ genericParamText << " <#" << genericParam->getName () << " : " ;
1507
+ genericParamText << type << " #>" ;
1509
1508
return ;
1510
1509
}
1511
1510
1512
- genericParamText << " <#" << genericParam->getName () << " : " ;
1513
- interleave (protocols,
1514
- [&](const ProtocolDecl *proto) {
1515
- genericParamText << proto->getName ();
1516
- },
1517
- [&] { genericParamText << " & " ; });
1518
- genericParamText << " #>" ;
1511
+ genericParamText << contextTy;
1519
1512
};
1520
1513
1521
1514
interleave (typeDecl->getInnermostGenericParamTypes (),
0 commit comments