Skip to content

Commit f3b7b8c

Browse files
authored
Merge pull request #15035 from slavapestov/print-extended-type-name
AST: Simplify printExtendedTypeName()
2 parents e11b5b8 + cb1c8c8 commit f3b7b8c

File tree

3 files changed

+267
-292
lines changed

3 files changed

+267
-292
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,28 +1758,13 @@ void PrintAST::visitImportDecl(ImportDecl *decl) {
17581758

17591759
static void printExtendedTypeName(Type ExtendedType, ASTPrinter &Printer,
17601760
PrintOptions Options) {
1761-
auto Nominal = ExtendedType->getAnyNominal();
1762-
assert(Nominal && "extension of non-nominal type");
1763-
if (auto nt = ExtendedType->getAs<NominalType>()) {
1764-
if (auto ParentType = nt->getParent()) {
1765-
if (auto *ParentNT = ParentType->getAs<NominalOrBoundGenericNominalType>()) {
1766-
// Avoid using the parent type directly because it can be bound
1767-
// generic type and sugared.
1768-
ParentNT->getDecl()->getDeclaredType().print(Printer, Options);
1769-
} else {
1770-
ParentType.print(Printer, Options);
1771-
}
1772-
Printer << ".";
1773-
}
1774-
}
1761+
Options.FullyQualifiedTypes = false;
1762+
Options.FullyQualifiedTypesIfAmbiguous = false;
17751763

1776-
// Respect alias type.
1777-
if (isa<NameAliasType>(ExtendedType.getPointer())) {
1778-
ExtendedType.print(Printer, Options);
1779-
return;
1780-
}
1764+
// Strip off generic arguments, if any.
1765+
auto Ty = ExtendedType->getAnyNominal()->getDeclaredType();
17811766

1782-
Printer.printTypeRef(ExtendedType, Nominal, Nominal->getName());
1767+
Ty->print(Printer, Options);
17831768
}
17841769

17851770
void PrintAST::printSynthesizedExtension(Type ExtendedType,

test/IDE/print_synthesized_extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ extension S13 : P5 {
294294
// CHECK9-NEXT: <decl:Func>public func <loc>ef5(<decl:Param>t: <ref:Struct>S5</ref></decl>)</loc></decl>
295295
// CHECK9-NEXT: }</synthesized>
296296

297-
// CHECK10: <synthesized>extension <ref:module>print_synthesized_extensions</ref>.<ref:Struct>S7</ref>.<ref:Struct>S8</ref> {
297+
// CHECK10: <synthesized>extension <ref:Struct>S7</ref>.<ref:Struct>S8</ref> {
298298
// CHECK10-NEXT: <decl:Func>public func <loc>p3Func(<decl:Param>i: <ref:Struct>Int</ref></decl>)</loc> -> <ref:Struct>Int</ref></decl>
299299
// CHECK10-NEXT: <decl:Func>public func <loc>ef5(<decl:Param>t: <ref:Struct>S5</ref></decl>)</loc></decl>
300300
// CHECK10-NEXT: }</synthesized>

0 commit comments

Comments
 (0)