@@ -932,6 +932,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
932
932
PrintRequirements = 2 ,
933
933
InnermostOnly = 4 ,
934
934
SkipSelfRequirement = 8 ,
935
+ SwapSelfAndDependentMemberType = 16 ,
935
936
};
936
937
937
938
void printWhereClauseFromRequirementSignature (ProtocolDecl *proto,
@@ -1323,8 +1324,11 @@ bestRequirementPrintLocation(ProtocolDecl *proto, const Requirement &req) {
1323
1324
void PrintAST::printWhereClauseFromRequirementSignature (ProtocolDecl *proto,
1324
1325
Decl *attachingTo) {
1325
1326
assert (proto->isRequirementSignatureComputed ());
1327
+ unsigned flags = PrintRequirements;
1328
+ if (isa<AssociatedTypeDecl>(attachingTo))
1329
+ flags |= SwapSelfAndDependentMemberType;
1326
1330
printGenericSignature (
1327
- proto->getRequirementSignature (), PrintRequirements ,
1331
+ proto->getRequirementSignature (), flags ,
1328
1332
[&](const Requirement &req) {
1329
1333
auto location = bestRequirementPrintLocation (proto, req);
1330
1334
return location.AttachedTo == attachingTo && location.InWhereClause ;
@@ -1441,6 +1445,8 @@ void PrintAST::printSingleDepthOfGenericSignature(
1441
1445
llvm::function_ref<bool (const Requirement &)> filter) {
1442
1446
bool printParams = (flags & PrintParams);
1443
1447
bool printRequirements = (flags & PrintRequirements);
1448
+ bool swapSelfAndDependentMemberType =
1449
+ (flags & SwapSelfAndDependentMemberType);
1444
1450
1445
1451
SubstitutionMap subMap;
1446
1452
if (CurrentType) {
@@ -1517,6 +1523,13 @@ void PrintAST::printSingleDepthOfGenericSignature(
1517
1523
Printer << " , " ;
1518
1524
}
1519
1525
1526
+ // Swap the order of Self == Self.A requirements if requested.
1527
+ if (swapSelfAndDependentMemberType &&
1528
+ req.getKind () == RequirementKind::SameType &&
1529
+ first->is <GenericTypeParamType>() &&
1530
+ second->is <DependentMemberType>())
1531
+ std::swap (first, second);
1532
+
1520
1533
Printer.callPrintStructurePre (PrintStructureKind::GenericRequirement);
1521
1534
if (second) {
1522
1535
Requirement substReq (req.getKind (), first, second);
0 commit comments