Skip to content

Commit 7a04fc9

Browse files
committed
ASTPrinter: Don't print redundant 'where Self : AnyObject'
1 parent 50e7c06 commit 7a04fc9

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
@@ -915,8 +915,12 @@ bestRequirementPrintLocation(ProtocolDecl *proto, const Requirement &req) {
915915

916916
// A requirement like Self : Protocol or Self.T : Class might be from an
917917
// inheritance, or might be a where clause.
918-
if (req.getKind() != RequirementKind::Layout && result.second) {
919-
auto inherited = req.getSecondType();
918+
if (result.second) {
919+
Type inherited;
920+
if (req.getKind() == RequirementKind::Layout)
921+
inherited = proto->getASTContext().getAnyObjectType();
922+
else
923+
inherited = req.getSecondType();
920924
inWhereClause =
921925
none_of(result.first->getInherited(), [&](const TypeLoc &loc) {
922926
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
@@ -599,7 +599,7 @@ func hasLocalizationKey2() {}
599599
// FIXME: ref.class - rdar://problem/25014968
600600

601601
// 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
602-
// 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>
602+
// 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>
603603

604604
// 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
605605
// CHECK67: source.lang.swift.decl.associatedtype (114:18-114:19)

0 commit comments

Comments
 (0)