Skip to content

Commit c4d7b1a

Browse files
committed
ASTPrinter: never synthesize extensions for raw types of enum decls.
Even thought raw types are specified in inheritance clauses, their members are not usable through an enum instance. Thus, there is no point to synthesize their members.
1 parent d39e7d9 commit c4d7b1a

File tree

3 files changed

+2568
-7432
lines changed

3 files changed

+2568
-7432
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,14 @@ struct SynthesizedExtensionAnalyzer::Implementation {
528528
return InfoMap;
529529
}
530530

531+
static bool isEnumRawType(const Decl* D, TypeLoc TL) {
532+
assert (TL.getType());
533+
if (auto ED = dyn_cast<EnumDecl>(D)) {
534+
return ED->hasRawType() && ED->getRawType()->isEqual(TL.getType());
535+
}
536+
return false;
537+
}
538+
531539
std::unique_ptr<ExtensionInfoMap>
532540
collectSynthesizedExtensionInfo(MergeGroupVector &AllGroups) {
533541
if (Target->getKind() == DeclKind::Protocol) {
@@ -544,7 +552,8 @@ struct SynthesizedExtensionAnalyzer::Implementation {
544552
}
545553
};
546554
for (auto TL : Target->getInherited()) {
547-
addTypeLocNominal(TL);
555+
if (!isEnumRawType(Target, TL))
556+
addTypeLocNominal(TL);
548557
}
549558
while (!Unhandled.empty()) {
550559
NominalTypeDecl* Back = Unhandled.back();
@@ -558,7 +567,8 @@ struct SynthesizedExtensionAnalyzer::Implementation {
558567
MergeInfoMap.insert({E, Pair.second});
559568
}
560569
for (auto TL : Back->getInherited()) {
561-
addTypeLocNominal(TL);
570+
if (!isEnumRawType(Target, TL))
571+
addTypeLocNominal(TL);
562572
}
563573
}
564574
}

0 commit comments

Comments
 (0)