Skip to content

Commit 5cff292

Browse files
authored
Merge pull request swiftlang#41005 from CodaFi/stubbed-toe
Propagate Qualified Type Printing in Ambiguous Situations In More Cases
2 parents 65f6ea3 + d5c226d commit 5cff292

12 files changed

+439
-355
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,8 @@ class PrintAST : public ASTVisitor<PrintAST> {
753753
FreshOptions.ExclusiveAttrList = options.ExclusiveAttrList;
754754
FreshOptions.PrintOptionalAsImplicitlyUnwrapped = options.PrintOptionalAsImplicitlyUnwrapped;
755755
FreshOptions.TransformContext = options.TransformContext;
756+
FreshOptions.CurrentModule = options.CurrentModule;
757+
FreshOptions.FullyQualifiedTypesIfAmbiguous = options.FullyQualifiedTypesIfAmbiguous;
756758
T.print(Printer, FreshOptions);
757759
return;
758760
}

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3562,6 +3562,7 @@ printRequirementStub(ValueDecl *Requirement, DeclContext *Adopter,
35623562
Options.SkipAttributes = true;
35633563
Options.FunctionDefinitions = true;
35643564
Options.PrintAccessorBodiesInProtocols = true;
3565+
Options.FullyQualifiedTypesIfAmbiguous = true;
35653566

35663567
bool AdopterIsClass = Adopter->getSelfClassDecl() != nullptr;
35673568
// Skip 'mutating' only inside classes: mutating methods usually

test/IDE/print_synthesized_extensions.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,21 +239,21 @@ extension S13 : P5 {
239239
public func foo1() {}
240240
}
241241

242-
// CHECK1: <synthesized>extension <ref:Struct>S1</ref> where <ref:GenericTypeParam>T</ref> : <ref:Protocol>P2</ref> {
242+
// CHECK1: <synthesized>extension <ref:Struct>S1</ref> where <ref:GenericTypeParam>T</ref> : <ref:module>print_synthesized_extensions</ref>.<ref:Protocol>P2</ref> {
243243
// CHECK1-NEXT: <decl:Func>public func <loc>p2member()</loc></decl>
244244
// CHECK1-NEXT: <decl:Func>public func <loc>ef1(<decl:Param>t: <ref:GenericTypeParam>T</ref></decl>)</loc></decl>
245-
// CHECK1-NEXT: <decl:Func>public func <loc>ef2(<decl:Param>t: <ref:Struct>S2</ref></decl>)</loc></decl>
245+
// CHECK1-NEXT: <decl:Func>public func <loc>ef2(<decl:Param>t: <ref:module>print_synthesized_extensions</ref>.<ref:Struct>S2</ref></decl>)</loc></decl>
246246
// CHECK1-NEXT: }</synthesized>
247247

248-
// CHECK2: <synthesized>extension <ref:Struct>S1</ref> where <ref:GenericTypeParam>T</ref> : <ref:Protocol>P3</ref> {
248+
// CHECK2: <synthesized>extension <ref:Struct>S1</ref> where <ref:GenericTypeParam>T</ref> : <ref:module>print_synthesized_extensions</ref>.<ref:Protocol>P3</ref> {
249249
// CHECK2-NEXT: <decl:Func>public func <loc>p3Func(<decl:Param>i: <ref:Struct>Int</ref></decl>)</loc> -> <ref:Struct>Int</ref></decl>
250250
// CHECK2-NEXT: }</synthesized>
251251

252252
// CHECK3: <synthesized>extension <ref:Struct>S1</ref> where <ref:GenericTypeParam>T</ref> == <ref:Struct>Int</ref> {
253253
// CHECK3-NEXT: <decl:Func>public func <loc>p1IntFunc(<decl:Param>i: <ref:Struct>Int</ref></decl>)</loc> -> <ref:Struct>Int</ref></decl>
254254
// CHECK3-NEXT: }</synthesized>
255255

256-
// CHECK4: <synthesized>extension <ref:Struct>S1</ref> where <ref:GenericTypeParam>T</ref> == <ref:Struct>S9</ref><<ref:Struct>Int</ref>> {
256+
// CHECK4: <synthesized>extension <ref:Struct>S1</ref> where <ref:GenericTypeParam>T</ref> == <ref:module>print_synthesized_extensions</ref>.<ref:Struct>S9</ref><<ref:Struct>Int</ref>> {
257257
// CHECK4-NEXT: <decl:Func>public func <loc>S9IntFunc()</loc></decl>
258258
// CHECK4-NEXT: }</synthesized>
259259

@@ -263,7 +263,7 @@ extension S13 : P5 {
263263
// CHECK5-NEXT: <decl:Func>public func <loc>f1(<decl:Param>t: <ref:module>print_synthesized_extensions</ref>.<ref:Struct>S10</ref>.<ref:TypeAlias>T1</ref></decl>)</loc> -> <ref:module>print_synthesized_extensions</ref>.<ref:Struct>S10</ref>.<ref:TypeAlias>T1</ref></decl>
264264
// CHECK5-NEXT: <decl:Func>public func <loc>f2(<decl:Param>t: <ref:module>print_synthesized_extensions</ref>.<ref:Struct>S10</ref>.<ref:TypeAlias>T2</ref></decl>)</loc> -> <ref:module>print_synthesized_extensions</ref>.<ref:Struct>S10</ref>.<ref:TypeAlias>T2</ref></decl></decl>
265265
// CHECK5-NEXT: <decl:Func>public func <loc>p3Func(<decl:Param>i: <ref:Struct>Int</ref></decl>)</loc> -> <ref:Struct>Int</ref></decl>
266-
// CHECK5-NEXT: <decl:Func>public func <loc>ef5(<decl:Param>t: <ref:Struct>S9</ref><<ref:Struct>Int</ref>></decl>)</loc></decl>
266+
// CHECK5-NEXT: <decl:Func>public func <loc>ef5(<decl:Param>t: <ref:module>print_synthesized_extensions</ref>.<ref:Struct>S9</ref><<ref:Struct>Int</ref>></decl>)</loc></decl>
267267
// CHECK5-NEXT: <decl:Func>public func <loc>S9IntFunc()</loc></decl>
268268
// CHECK5-NEXT: }</synthesized>
269269

@@ -294,12 +294,12 @@ extension S13 : P5 {
294294
// CHECK9-NEXT: <decl:Extension><decl:Func>public func <loc>f3()</loc></decl></decl>
295295
// CHECK9-NEXT: <decl:Extension><decl:Func>public func <loc>fromActualExtension()</loc></decl></decl>
296296
// CHECK9-NEXT: <decl:Func>public func <loc>p3Func(<decl:Param>i: <ref:Struct>Int</ref></decl>)</loc> -> <ref:Struct>Int</ref></decl>
297-
// CHECK9-NEXT: <decl:Func>public func <loc>ef5(<decl:Param>t: <ref:Struct>S5</ref></decl>)</loc></decl>
297+
// CHECK9-NEXT: <decl:Func>public func <loc>ef5(<decl:Param>t: <ref:module>print_synthesized_extensions</ref>.<ref:Struct>S5</ref></decl>)</loc></decl>
298298
// CHECK9-NEXT: }</synthesized>
299299

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

305305
// CHECK11: <decl:Struct>public struct <loc>S12</loc> : <ref:module>print_synthesized_extensions</ref>.<ref:Protocol>P5</ref> {
@@ -376,7 +376,7 @@ extension C : P8 {}
376376
// CHECK15-NEXT: <decl:Func>public func <loc>bar()</loc></decl>
377377
// CHECK15-NEXT: }</synthesized>
378378

379-
// CHECK15: <synthesized>extension <ref:Class>C</ref> where <ref:GenericTypeParam>T</ref> : <ref:Class>E</ref> {
379+
// CHECK15: <synthesized>extension <ref:Class>C</ref> where <ref:GenericTypeParam>T</ref> : <ref:module>print_synthesized_extensions</ref>.<ref:Class>E</ref> {
380380
// CHECK15-NEXT: <decl:Func>public func <loc>baz()</loc></decl>
381381
// CHECK15-NEXT: }</synthesized>
382382

@@ -397,4 +397,4 @@ extension F : P8 {}
397397
// CHECK16-NEXT: <decl:Func>public func <loc>bar()</loc></decl>
398398
// CHECK16-NEXT: }</synthesized>
399399

400-
// CHECK16-NOT: <synthesized>extension <ref:Class>F</ref> where <ref:GenericTypeParam>T</ref> : <ref:Class>E</ref> {
400+
// CHECK16-NOT: <synthesized>extension <ref:Class>F</ref> where <ref:GenericTypeParam>T</ref> : <ref:module>print_synthesized_extensions</ref>.<ref:Class>E</ref> {

test/IDE/print_synthesized_extensions_generics.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ extension P1 where T : B<Int> {
1919

2020
public class C<T : A, U> {}
2121
extension C : P1 {}
22-
// CHECK: extension C where T : B<U> {
22+
// CHECK: extension C where T : print_synthesized_extensions_generics.B<U> {
2323
// CHECK-NEXT: func qux()
2424
// CHECK-NEXT: }
2525

26-
// CHECK: extension C where T : B<Int> {
26+
// CHECK: extension C where T : print_synthesized_extensions_generics.B<Int> {
2727
// CHECK-NEXT: func flob()
2828
// CHECK-NEXT: }
2929

@@ -70,7 +70,7 @@ extension P2 where T.T : A {
7070
public class G<T : P1> {}
7171
extension G : P2 {}
7272

73-
// CHECK: extension G where T.T : A {
73+
// CHECK: extension G where T.T : print_synthesized_extensions_generics.A {
7474
// CHECK-NEXT: func blah()
7575
// CHECK-NEXT: }
7676

test/IDE/print_synthesized_extensions_superclass.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ public struct S5 : P {
9494
// CHECK-NEXT: public func withBase()
9595
// CHECK-NEXT: }
9696

97-
// CHECK-LABEL: extension S6 where T : Middle<U> {
97+
// CHECK-LABEL: extension S6 where T : print_synthesized_extensions_superclass.Middle<U> {
9898
// CHECK-NEXT: public func withMiddleAbstract()
9999
// CHECK-NEXT: }
100100

101-
// CHECK-LABEL: extension S6 where T : Middle<Int> {
101+
// CHECK-LABEL: extension S6 where T : print_synthesized_extensions_superclass.Middle<Int> {
102102
// CHECK-NEXT: public func withMiddleConcrete()
103103
// CHECK-NEXT: }
104104

105-
// CHECK-LABEL: extension S6 where T : Most {
105+
// CHECK-LABEL: extension S6 where T : print_synthesized_extensions_superclass.Most {
106106
// CHECK-NEXT: public func withMost()
107107
// CHECK-NEXT: }
108108

@@ -113,11 +113,11 @@ public struct S6<T, U> : P where T : Base {}
113113
// CHECK-NEXT: public func withMiddleAbstract()
114114
// CHECK-NEXT: }
115115

116-
// CHECK-LABEL: extension S7 where T : Middle<Int> {
116+
// CHECK-LABEL: extension S7 where T : print_synthesized_extensions_superclass.Middle<Int> {
117117
// CHECK-NEXT: public func withMiddleConcrete()
118118
// CHECK-NEXT: }
119119

120-
// CHECK-LABEL: extension S7 where T : Most {
120+
// CHECK-LABEL: extension S7 where T : print_synthesized_extensions_superclass.Most {
121121
// CHECK-NEXT: public func withMost()
122122
// CHECK-NEXT: }
123123

@@ -129,4 +129,4 @@ public struct S7<T, U> : P where T : Middle<U> {}
129129
// CHECK-NEXT: public func withMost()
130130
// CHECK-NEXT: }
131131

132-
public struct S8<T, U> : P where T : Most {}
132+
public struct S8<T, U> : P where T : Most {}

test/IDE/print_type_interface.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ class C2 {
3939
}
4040
}
4141

42-
// RUN: %target-swift-ide-test -print-type-interface -pos=37:6 -source-filename %s | %FileCheck %s -check-prefix=TYPE2
42+
// RUN: %target-swift-ide-test -print-type-interface -pos=37:6 -module-name print_type_interface -source-filename %s | %FileCheck %s -check-prefix=TYPE2
4343
// RUN: %target-swift-ide-test -print-type-interface -usr=_TtGC20print_type_interface1DCS_2T1_ -module-name print_type_interface -source-filename %s | %FileCheck %s -check-prefix=TYPE2
44-
// RUN: %target-swift-ide-test -print-type-interface -pos=38:6 -source-filename %s | %FileCheck %s -check-prefix=TYPE3
44+
// RUN: %target-swift-ide-test -print-type-interface -pos=38:6 -module-name print_type_interface -source-filename %s | %FileCheck %s -check-prefix=TYPE3
4545
// RUN: %target-swift-ide-test -print-type-interface -usr=_TtGC20print_type_interface1DSi_ -module-name print_type_interface -source-filename %s | %FileCheck %s -check-prefix=TYPE3
4646

4747
extension D where T : P1 {
@@ -54,12 +54,12 @@ extension D {
5454
public func unconditionalFunc2(t : T) -> T {return t}
5555
}
5656

57-
// TYPE2: public class D<T1> {
57+
// TYPE2: public class D<print_type_interface.T1> {
5858
// TYPE2: public func foo()
5959
// TYPE2: public func conditionalFunc1()
60-
// TYPE2: public func conditionalFunc2(t: T1) -> T1
60+
// TYPE2: public func conditionalFunc2(t: print_type_interface.T1) -> print_type_interface.T1
6161
// TYPE2: public func unconditionalFunc1()
62-
// TYPE2: public func unconditionalFunc2(t: T1) -> T1
62+
// TYPE2: public func unconditionalFunc2(t: print_type_interface.T1) -> print_type_interface.T1
6363
// TYPE2: }
6464

6565
// TYPE3: public class D<Int> {

test/SourceKit/DocSupport/doc_generic_type_with_self_param.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public extension Proto {
2222
// paramter of `AttributedSlice1<T>`) and an unbound generic paramters.
2323
// This used to cause issues when printing the type.
2424
func formatted<S>(width: ListFormatStyle<S, Self>.Width) -> String {
25-
// CHECK: func formatted<S>(width width: ListFormatStyle<S, AttributesSlice1<T>>.Width) -> String
25+
// CHECK: func formatted<S>(width width: test.ListFormatStyle<S, test.AttributesSlice1<T>>.Width) -> String
2626
fatalError()
2727
}
2828
}

0 commit comments

Comments
 (0)