@@ -4115,7 +4115,6 @@ CanType ProtocolCompositionType::getMinimalCanonicalType(
4115
4115
return Reqs.front ().getSecondType ()->getCanonicalType ();
4116
4116
}
4117
4117
4118
- Type superclass;
4119
4118
llvm::SmallVector<Type, 2 > MinimalMembers;
4120
4119
bool MinimalHasExplicitAnyObject = false ;
4121
4120
auto ifaceTy = Sig.getGenericParams ().back ();
@@ -4126,10 +4125,6 @@ CanType ProtocolCompositionType::getMinimalCanonicalType(
4126
4125
4127
4126
switch (Req.getKind ()) {
4128
4127
case RequirementKind::Superclass:
4129
- assert ((!superclass || superclass->isEqual (Req.getSecondType ()))
4130
- && " Multiple distinct superclass constraints!" );
4131
- superclass = Req.getSecondType ();
4132
- break ;
4133
4128
case RequirementKind::Conformance:
4134
4129
MinimalMembers.push_back (Req.getSecondType ());
4135
4130
break ;
@@ -4141,10 +4136,16 @@ CanType ProtocolCompositionType::getMinimalCanonicalType(
4141
4136
}
4142
4137
}
4143
4138
4144
- // Ensure superclass bounds appear first regardless of their order among
4145
- // the signature's requirements.
4146
- if (superclass)
4147
- MinimalMembers.insert (MinimalMembers.begin (), superclass->getCanonicalType ());
4139
+ // A superclass constraint is always retained and must appear first in the
4140
+ // members list.
4141
+ assert (Composition->getMembers ().front ()->getClassOrBoundGenericClass () ==
4142
+ MinimalMembers.front ()->getClassOrBoundGenericClass ());
4143
+
4144
+ // If we are left with a single member and no layout constraint, the member
4145
+ // is the minimal type. Also, note that a protocol composition cannot be
4146
+ // constructed with a single member unless there is a layout constraint.
4147
+ if (MinimalMembers.size () == 1 && !MinimalHasExplicitAnyObject)
4148
+ return CanType (MinimalMembers.front ());
4148
4149
4149
4150
// The resulting composition is necessarily canonical.
4150
4151
return CanType (build (Ctx, MinimalMembers, MinimalHasExplicitAnyObject));
0 commit comments