Skip to content

Commit 4934207

Browse files
Merge pull request #38015 from varungandhi-apple/vg-5.5-interface-respect-flag
[5.5] [ASTPrinter] Use TypeLoc printing for extended types.
2 parents 1ca505b + c720c2c commit 4934207

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
@@ -919,6 +919,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
919919
void printSynthesizedExtension(Type ExtendedType, ExtensionDecl *ExtDecl);
920920

921921
void printExtension(ExtensionDecl* ExtDecl);
922+
void printExtendedTypeName(TypeLoc ExtendedTypeLoc);
922923

923924
public:
924925
PrintAST(ASTPrinter &Printer, const PrintOptions &Options)
@@ -2337,8 +2338,7 @@ void PrintAST::visitImportDecl(ImportDecl *decl) {
23372338
[&] { Printer << "."; });
23382339
}
23392340

2340-
static void printExtendedTypeName(Type ExtendedType, ASTPrinter &Printer,
2341-
PrintOptions &Options) {
2341+
void PrintAST::printExtendedTypeName(TypeLoc ExtendedTypeLoc) {
23422342
bool OldFullyQualifiedTypesIfAmbiguous =
23432343
Options.FullyQualifiedTypesIfAmbiguous;
23442344
Options.FullyQualifiedTypesIfAmbiguous =
@@ -2348,9 +2348,8 @@ static void printExtendedTypeName(Type ExtendedType, ASTPrinter &Printer,
23482348
};
23492349

23502350
// Strip off generic arguments, if any.
2351-
auto Ty = ExtendedType->getAnyNominal()->getDeclaredType();
2352-
2353-
Ty->print(Printer, Options);
2351+
auto Ty = ExtendedTypeLoc.getType()->getAnyNominal()->getDeclaredType();
2352+
printTypeLoc(TypeLoc(ExtendedTypeLoc.getTypeRepr(), Ty));
23542353
}
23552354

23562355

@@ -2408,7 +2407,7 @@ void PrintAST::printSynthesizedExtension(Type ExtendedType,
24082407
printAttributes(ExtDecl);
24092408
Printer << tok::kw_extension << " ";
24102409

2411-
printExtendedTypeName(ExtendedType, Printer, Options);
2410+
printExtendedTypeName(TypeLoc::withoutLoc(ExtendedType));
24122411
printInherited(ExtDecl);
24132412

24142413
// We may need to combine requirements from ExtDecl (which has the members
@@ -2459,7 +2458,7 @@ void PrintAST::printExtension(ExtensionDecl *decl) {
24592458
printTypeLoc(TypeLoc::withoutLoc(extendedType));
24602459
return;
24612460
}
2462-
printExtendedTypeName(extendedType, Printer, Options);
2461+
printExtendedTypeName(TypeLoc(decl->getExtendedTypeRepr(), extendedType));
24632462
});
24642463
printInherited(decl);
24652464

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)