Skip to content

Commit 994a5da

Browse files
committed
[AST Printer] Associate "Self == Self.Foo requirements with "Foo".
1 parent 9aed438 commit 994a5da

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,9 @@ bestRequirementPrintLocation(ProtocolDecl *proto, const Requirement &req) {
13001300
// Self.T.U == Self should go on T (third condition).
13011301
auto rhsBetterDirect =
13021302
!lhsResult.second && rhsResult.second && rhsResult.first != proto;
1303-
if (lhsDoesntExist || rhsBetterDirect)
1303+
auto rhsOfSelfToAssoc = lhsResult.first == proto && rhsResult.first;
1304+
// e.g. Self == Self.T.U
1305+
if (lhsDoesntExist || rhsBetterDirect || rhsOfSelfToAssoc)
13041306
bestDecl = rhsResult.first;
13051307

13061308
// Same-type requirements can only occur in where clauses

test/IDE/print_ast_tc_decls.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,13 +1339,13 @@ protocol ProtocolWithWhereClause : QuxProtocol where Qux == Int, Self : FooProto
13391339
// PREFER_TYPE_REPR_PRINTING: protocol ProtocolWithWhereClause : QuxProtocol where Self : FooProtocol, Self.Qux == Int {
13401340

13411341
protocol ProtocolWithWhereClauseAndAssoc : QuxProtocol where Qux == Int, Self : FooProtocol {
1342-
// PREFER_TYPE_REPR_PRINTING-DAG: protocol ProtocolWithWhereClauseAndAssoc : QuxProtocol where Self : FooProtocol, Self == Self.A2.Qux, Self.Qux == Int {
1342+
// PREFER_TYPE_REPR_PRINTING-DAG: protocol ProtocolWithWhereClauseAndAssoc : QuxProtocol where Self : FooProtocol, Self.Qux == Int {
13431343
associatedtype A1 : QuxProtocol where A1 : FooProtocol, A1.Qux : QuxProtocol, Int == A1.Qux.Qux
13441344
// PREFER_TYPE_REPR_PRINTING-DAG: {{^}} associatedtype A1 : QuxProtocol where Self.A1 : FooProtocol, Self.A1.Qux : QuxProtocol, Self.A1.Qux.Qux == Int{{$}}
13451345

13461346
// FIXME: this same type requirement with Self should be printed here
13471347
associatedtype A2 : QuxProtocol where A2.Qux == Self
1348-
// PREFER_TYPE_REPR_PRINTING-DAG: {{^}} associatedtype A2 : QuxProtocol{{$}}
1348+
// PREFER_TYPE_REPR_PRINTING-DAG: {{^}} associatedtype A2 : QuxProtocol where Self == Self.A2.Qux{{$}}
13491349
}
13501350

13511351
#if true

0 commit comments

Comments
 (0)