Skip to content

Commit f632363

Browse files
committed
AST: Clean up GenericSignatureImpl::getNonDependentUpperBounds()
1 parent c7e7b81 commit f632363

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

lib/AST/GenericSignature.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,8 @@ unsigned GenericSignatureImpl::getGenericParamOrdinal(
598598
Type GenericSignatureImpl::getNonDependentUpperBounds(Type type) const {
599599
assert(type->isTypeParameter());
600600

601+
bool hasExplicitAnyObject = requiresClass(type);
602+
601603
llvm::SmallVector<Type, 2> types;
602604
if (Type superclass = getSuperclassBound(type)) {
603605
// If the class contains a type parameter, try looking for a non-dependent
@@ -606,24 +608,28 @@ Type GenericSignatureImpl::getNonDependentUpperBounds(Type type) const {
606608
superclass = superclass->getSuperclass();
607609
}
608610

609-
if (superclass)
611+
if (superclass) {
610612
types.push_back(superclass);
613+
hasExplicitAnyObject = false;
614+
}
611615
}
612-
for (const auto &elt : getRequiredProtocols(type)) {
613-
types.push_back(elt->getDeclaredInterfaceType());
616+
for (auto *proto : getRequiredProtocols(type)) {
617+
if (proto->requiresClass())
618+
hasExplicitAnyObject = false;
619+
620+
types.push_back(proto->getDeclaredInterfaceType());
614621
}
615622

616-
const auto layout = getLayoutConstraint(type);
617-
const auto boundsTy = ProtocolCompositionType::get(
623+
auto constraint = ProtocolCompositionType::get(
618624
getASTContext(), types,
619-
/*HasExplicitAnyObject=*/layout &&
620-
layout->getKind() == LayoutConstraintKind::Class);
625+
hasExplicitAnyObject);
621626

622-
if (boundsTy->isExistentialType()) {
623-
return ExistentialType::get(boundsTy);
627+
if (!constraint->isConstraintType()) {
628+
assert(constraint->getClassOrBoundGenericClass());
629+
return constraint;
624630
}
625631

626-
return boundsTy;
632+
return ExistentialType::get(constraint);
627633
}
628634

629635
Type GenericSignatureImpl::getDependentUpperBounds(Type type) const {

0 commit comments

Comments
 (0)