Skip to content

Commit c5b8d1a

Browse files
committed
Ensure that Superclass Requirements Appear First in Minimal Protocol Composites
The requirements are not always going to appear with superclass constraints last, so we still need to ensure that superclass bounds wind up at the head of the set of members.
1 parent d6186c9 commit c5b8d1a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/AST/Type.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4014,12 +4014,17 @@ CanType ProtocolCompositionType::getMinimalCanonicalType(
40144014
return Reqs.front().getSecondType()->getCanonicalType();
40154015
}
40164016

4017+
Type superclass;
40174018
llvm::SmallVector<Type, 2> MinimalMembers;
40184019
bool MinimalHasExplicitAnyObject = false;
40194020
for (const auto &Req : Reqs) {
40204021
switch (Req.getKind()) {
4021-
case RequirementKind::Conformance:
40224022
case RequirementKind::Superclass:
4023+
assert((!superclass || superclass->isEqual(Req.getSecondType()))
4024+
&& "Multiple distinct superclass constraints!");
4025+
superclass = Req.getSecondType();
4026+
break;
4027+
case RequirementKind::Conformance:
40234028
MinimalMembers.push_back(Req.getSecondType());
40244029
break;
40254030
case RequirementKind::Layout:
@@ -4030,6 +4035,11 @@ CanType ProtocolCompositionType::getMinimalCanonicalType(
40304035
}
40314036
}
40324037

4038+
// Ensure any superclass bounds appears first regardless of its order among
4039+
// the signature's requirements.
4040+
if (superclass)
4041+
MinimalMembers.insert(MinimalMembers.begin(), superclass->getCanonicalType());
4042+
40334043
// The resulting composition is necessarily canonical.
40344044
return CanType(build(Ctx, MinimalMembers, MinimalHasExplicitAnyObject));
40354045
}

0 commit comments

Comments
 (0)