Skip to content

Commit 8ccc176

Browse files
Merge pull request swiftlang#38014 from varungandhi-apple/vg-interface-respect-flag
[ASTPrinter] Use TypeLoc printing for extended types.
2 parents 7a1ab7a + 284fcb5 commit 8ccc176

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
913913
void printSynthesizedExtension(Type ExtendedType, ExtensionDecl *ExtDecl);
914914

915915
void printExtension(ExtensionDecl* ExtDecl);
916+
void printExtendedTypeName(TypeLoc ExtendedTypeLoc);
916917

917918
public:
918919
PrintAST(ASTPrinter &Printer, const PrintOptions &Options)
@@ -2331,8 +2332,7 @@ void PrintAST::visitImportDecl(ImportDecl *decl) {
23312332
[&] { Printer << "."; });
23322333
}
23332334

2334-
static void printExtendedTypeName(Type ExtendedType, ASTPrinter &Printer,
2335-
PrintOptions &Options) {
2335+
void PrintAST::printExtendedTypeName(TypeLoc ExtendedTypeLoc) {
23362336
bool OldFullyQualifiedTypesIfAmbiguous =
23372337
Options.FullyQualifiedTypesIfAmbiguous;
23382338
Options.FullyQualifiedTypesIfAmbiguous =
@@ -2342,9 +2342,8 @@ static void printExtendedTypeName(Type ExtendedType, ASTPrinter &Printer,
23422342
};
23432343

23442344
// Strip off generic arguments, if any.
2345-
auto Ty = ExtendedType->getAnyNominal()->getDeclaredType();
2346-
2347-
Ty->print(Printer, Options);
2345+
auto Ty = ExtendedTypeLoc.getType()->getAnyNominal()->getDeclaredType();
2346+
printTypeLoc(TypeLoc(ExtendedTypeLoc.getTypeRepr(), Ty));
23482347
}
23492348

23502349

@@ -2402,7 +2401,7 @@ void PrintAST::printSynthesizedExtension(Type ExtendedType,
24022401
printAttributes(ExtDecl);
24032402
Printer << tok::kw_extension << " ";
24042403

2405-
printExtendedTypeName(ExtendedType, Printer, Options);
2404+
printExtendedTypeName(TypeLoc::withoutLoc(ExtendedType));
24062405
printInherited(ExtDecl);
24072406

24082407
// We may need to combine requirements from ExtDecl (which has the members
@@ -2453,7 +2452,7 @@ void PrintAST::printExtension(ExtensionDecl *decl) {
24532452
printTypeLoc(TypeLoc::withoutLoc(extendedType));
24542453
return;
24552454
}
2456-
printExtendedTypeName(extendedType, Printer, Options);
2455+
printExtendedTypeName(TypeLoc(decl->getExtendedTypeRepr(), extendedType));
24572456
});
24582457
printInherited(decl);
24592458

test/ModuleInterface/preserve-type-repr.swift

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1-
// RUN: %target-swift-frontend -typecheck -emit-module-interface-path - %s -enable-library-evolution -module-name PreferTypeRepr -module-interface-preserve-types-as-written | %FileCheck %s --check-prefix PREFER
2-
// RUN: %target-swift-frontend -typecheck -emit-module-interface-path - %s -enable-library-evolution -module-name PreferTypeRepr | %FileCheck %s --check-prefix DONTPREFER
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %s -typecheck -enable-library-evolution -emit-module-interface-path %t/External.swiftinterface -module-name External -DEXTERNAL
3+
// RUN: %target-swift-frontend -typecheck -emit-module-interface-path - %s -enable-library-evolution -module-name PreferTypeRepr -module-interface-preserve-types-as-written -I %t | %FileCheck %s --check-prefix PREFER
4+
// RUN: %target-swift-frontend -typecheck -emit-module-interface-path - %s -enable-library-evolution -module-name PreferTypeRepr -I %t | %FileCheck %s --check-prefix DONTPREFER
5+
6+
#if EXTERNAL
7+
public struct Toy {
8+
public init() {}
9+
}
10+
11+
public struct GenericToy<T> {
12+
public init() {}
13+
}
14+
#else
15+
import External
16+
17+
// PREFER: extension Toy
18+
// DONTPREFER: extension External.Toy
19+
extension Toy {
20+
public static var new: Toy { Toy() }
21+
}
22+
23+
// PREFER: extension GenericToy {
24+
// DONTPREFER: extension External.GenericToy {
25+
extension GenericToy {
26+
public static var new: GenericToy<T> { GenericToy() }
27+
}
328

429
public protocol Pet {}
530

@@ -32,3 +57,4 @@ extension My where T: Pet {
3257
// PREFER: public func isNoMore(_ pet: Ex<Parrot>) -> Bool
3358
// DONTPREFER: public func isNoMore(_ pet: PreferTypeRepr.Ex<PreferTypeRepr.Parrot>) -> Swift.Bool
3459
public func isNoMore(_ pet: Ex<Parrot>) -> Bool {}
60+
#endif

0 commit comments

Comments
 (0)