Skip to content

Commit 21fa797

Browse files
committed
ASTPrinter: Don't print redundant 'where Self : AnyObject'
1 parent 7f47f68 commit 21fa797

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,8 +1310,12 @@ bestRequirementPrintLocation(ProtocolDecl *proto, const Requirement &req) {
13101310

13111311
// A requirement like Self : Protocol or Self.T : Class might be from an
13121312
// inheritance, or might be a where clause.
1313-
if (req.getKind() != RequirementKind::Layout && result.second) {
1314-
auto inherited = req.getSecondType();
1313+
if (result.second) {
1314+
Type inherited;
1315+
if (req.getKind() == RequirementKind::Layout)
1316+
inherited = proto->getASTContext().getAnyObjectType();
1317+
else
1318+
inherited = req.getSecondType();
13151319
inWhereClause =
13161320
none_of(result.first->getInherited(), [&](const TypeLoc &loc) {
13171321
return loc.getType()->isEqual(inherited);

test/IDE/print_ast_tc_decls.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ protocol d0130_TestProtocol {
486486
}
487487

488488
protocol d0150_TestClassProtocol : class {}
489-
// PASS_COMMON-LABEL: {{^}}protocol d0150_TestClassProtocol : AnyObject where Self : AnyObject {{{$}}
489+
// PASS_COMMON-LABEL: {{^}}protocol d0150_TestClassProtocol : AnyObject {{{$}}
490490

491491
@objc protocol d0151_TestClassProtocol {}
492492
// PASS_COMMON-LABEL: {{^}}@objc protocol d0151_TestClassProtocol {{{$}}

test/SourceKit/CursorInfo/cursor_info.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ func hasLocalizationKey2() {}
600600
// FIXME: ref.class - rdar://problem/25014968
601601

602602
// RUN: %sourcekitd-test -req=cursor -pos=150:10 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | %FileCheck %s -check-prefix=CHECK66
603-
// CHECK66: <decl.protocol><syntaxtype.keyword>protocol</syntaxtype.keyword> <decl.name>P2</decl.name> : <ref.typealias usr="s:s9AnyObjecta">AnyObject</ref.typealias>, <ref.protocol usr="s:11cursor_info2P1P">P1</ref.protocol> <syntaxtype.keyword>where</syntaxtype.keyword> <decl.generic_type_requirement><ref.generic_type_param usr="s:11cursor_info2P2P4Selfxmfp">Self</ref.generic_type_param> : AnyObject</decl.generic_type_requirement></decl.protocol>
603+
// CHECK66: <decl.protocol><syntaxtype.keyword>protocol</syntaxtype.keyword> <decl.name>P2</decl.name> : <ref.typealias usr="s:s9AnyObjecta">AnyObject</ref.typealias>, <ref.protocol usr="s:11cursor_info2P1P">P1</ref.protocol></decl.protocol>
604604

605605
// RUN: %sourcekitd-test -req=cursor -pos=114:18 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | %FileCheck %s -check-prefix=CHECK67
606606
// CHECK67: source.lang.swift.decl.associatedtype (114:18-114:19)

0 commit comments

Comments
 (0)