Skip to content

Commit 93ec990

Browse files
committed
Sourcekit/DocSupport: avoid substituting generic types when printing where clauses. rdar://43820510
This makes the printed requirements agree with separately reported generic parameters and requirement.
1 parent d620dfa commit 93ec990

File tree

4 files changed

+872
-877
lines changed

4 files changed

+872
-877
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,13 +1406,10 @@ void PrintAST::printSingleDepthOfGenericSignature(
14061406
}
14071407
} else {
14081408
Printer.callPrintStructurePre(PrintStructureKind::GenericRequirement);
1409-
if (second) {
1410-
Requirement substReq(req.getKind(), first, second);
1411-
printRequirement(substReq);
1412-
} else {
1413-
Requirement substReq(req.getKind(), first, req.getLayoutConstraint());
1414-
printRequirement(substReq);
1415-
}
1409+
1410+
// We don't substitute type for the printed requirement so that the
1411+
// printed requirement agrees with separately reported generic parameters.
1412+
printRequirement(req);
14161413
Printer.printStructurePost(PrintStructureKind::GenericRequirement);
14171414
}
14181415
}

test/IDE/print_ast_tc_decls.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ protocol ProtocolWithWhereClauseAndAssoc : QuxProtocol where Qux == Int {
13581358

13591359
// FIXME: this same type requirement with Self should be printed here
13601360
associatedtype A2 : QuxProtocol where A2.Qux == Self
1361-
// PREFER_TYPE_REPR_PRINTING-DAG: {{^}} associatedtype A2 : QuxProtocol where Self.A2.Qux == Self{{$}}
1361+
// PREFER_TYPE_REPR_PRINTING-DAG: {{^}} associatedtype A2 : QuxProtocol where Self == Self.A2.Qux{{$}}
13621362
}
13631363

13641364
#if true

test/IDE/print_synthesized_extensions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,21 +237,21 @@ extension S13 : P5 {
237237
public func foo1() {}
238238
}
239239

240-
// CHECK1: <synthesized>extension <ref:Struct>S1</ref> where T : <ref:Protocol>P2</ref> {
240+
// CHECK1: <synthesized>extension <ref:Struct>S1</ref> where <ref:GenericTypeParam>Self</ref>.P2T1 : <ref:Protocol>P2</ref> {
241241
// CHECK1-NEXT: <decl:Func>public func <loc>p2member()</loc></decl>
242242
// CHECK1-NEXT: <decl:Func>public func <loc>ef1(<decl:Param>t: T</decl>)</loc></decl>
243243
// CHECK1-NEXT: <decl:Func>public func <loc>ef2(<decl:Param>t: <ref:Struct>S2</ref></decl>)</loc></decl>
244244
// CHECK1-NEXT: }</synthesized>
245245

246-
// CHECK2: <synthesized>extension <ref:Struct>S1</ref> where T : <ref:Protocol>P3</ref> {
246+
// CHECK2: <synthesized>extension <ref:Struct>S1</ref> where <ref:GenericTypeParam>Self</ref>.T1 : <ref:Protocol>P3</ref> {
247247
// CHECK2-NEXT: <decl:Func>public func <loc>p3Func(<decl:Param>i: <ref:Struct>Int</ref></decl>)</loc> -> <ref:Struct>Int</ref></decl>
248248
// CHECK2-NEXT: }</synthesized>
249249

250-
// CHECK3: <synthesized>extension <ref:Struct>S1</ref> where T == <ref:Struct>Int</ref> {
250+
// CHECK3: <synthesized>extension <ref:Struct>S1</ref> where <ref:GenericTypeParam>Self</ref>.T1 == <ref:Struct>Int</ref> {
251251
// CHECK3-NEXT: <decl:Func>public func <loc>p1IntFunc(<decl:Param>i: <ref:Struct>Int</ref></decl>)</loc> -> <ref:Struct>Int</ref></decl>
252252
// CHECK3-NEXT: }</synthesized>
253253

254-
// CHECK4: <synthesized>extension <ref:Struct>S1</ref> where T == <ref:Struct>S9</ref><<ref:Struct>Int</ref>> {
254+
// CHECK4: <synthesized>extension <ref:Struct>S1</ref> where <ref:GenericTypeParam>Self</ref>.T1 == <ref:Struct>S9</ref><<ref:Struct>Int</ref>> {
255255
// CHECK4-NEXT: <decl:Func>public func <loc>S9IntFunc()</loc></decl>
256256
// CHECK4-NEXT: }</synthesized>
257257

0 commit comments

Comments
 (0)