Skip to content

Commit 214c7f8

Browse files
committed
Sema: Update getDefaultGenericArgumentsString() for primitive AnyObject
1 parent b0360ce commit 214c7f8

File tree

1 file changed

+25
-32
lines changed

1 file changed

+25
-32
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,53 +1469,46 @@ bool TypeChecker::getDefaultGenericArgumentsString(
14691469
genericParamText << "<";
14701470

14711471
auto printGenericParamSummary =
1472-
[&](const GenericTypeParamType *genericParamTy) {
1472+
[&](GenericTypeParamType *genericParamTy) {
14731473
const GenericTypeParamDecl *genericParam = genericParamTy->getDecl();
14741474
if (Type result = getPreferredType(genericParam)) {
14751475
result.print(genericParamText);
14761476
return;
14771477
}
14781478

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;
14811482

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);
14871487
}
14881488

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;
14951493
}
1496-
genericParamText << "#>";
1497-
return;
1498-
}
14991494

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+
}
15041505

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 << "#>";
15091508
return;
15101509
}
15111510

1512-
genericParamText << "<#" << genericParam->getName() << ": ";
1513-
interleave(protocols,
1514-
[&](const ProtocolDecl *proto) {
1515-
genericParamText << proto->getName();
1516-
},
1517-
[&] { genericParamText << " & "; });
1518-
genericParamText << "#>";
1511+
genericParamText << contextTy;
15191512
};
15201513

15211514
interleave(typeDecl->getInnermostGenericParamTypes(),

0 commit comments

Comments
 (0)