@@ -598,6 +598,8 @@ unsigned GenericSignatureImpl::getGenericParamOrdinal(
598
598
Type GenericSignatureImpl::getNonDependentUpperBounds (Type type) const {
599
599
assert (type->isTypeParameter ());
600
600
601
+ bool hasExplicitAnyObject = requiresClass (type);
602
+
601
603
llvm::SmallVector<Type, 2 > types;
602
604
if (Type superclass = getSuperclassBound (type)) {
603
605
// If the class contains a type parameter, try looking for a non-dependent
@@ -606,24 +608,28 @@ Type GenericSignatureImpl::getNonDependentUpperBounds(Type type) const {
606
608
superclass = superclass->getSuperclass ();
607
609
}
608
610
609
- if (superclass)
611
+ if (superclass) {
610
612
types.push_back (superclass);
613
+ hasExplicitAnyObject = false ;
614
+ }
611
615
}
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 ());
614
621
}
615
622
616
- const auto layout = getLayoutConstraint (type);
617
- const auto boundsTy = ProtocolCompositionType::get (
623
+ auto constraint = ProtocolCompositionType::get (
618
624
getASTContext (), types,
619
- /* HasExplicitAnyObject=*/ layout &&
620
- layout->getKind () == LayoutConstraintKind::Class);
625
+ hasExplicitAnyObject);
621
626
622
- if (boundsTy->isExistentialType ()) {
623
- return ExistentialType::get (boundsTy);
627
+ if (!constraint->isConstraintType ()) {
628
+ assert (constraint->getClassOrBoundGenericClass ());
629
+ return constraint;
624
630
}
625
631
626
- return boundsTy ;
632
+ return ExistentialType::get (constraint) ;
627
633
}
628
634
629
635
Type GenericSignatureImpl::getDependentUpperBounds (Type type) const {
0 commit comments