Skip to content

Commit 85805f3

Browse files
author
Nathan Hawes
committed
[indexer] Fix missing references for inherits of associated types
E.g. MissedRef in: protocol Proto { associatedtype T : MissedRef } This resolved rdar://problem/25616751
1 parent 252af7d commit 85805f3

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

lib/AST/ASTWalker.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
197197
}
198198

199199
bool visitAbstractTypeParamDecl(AbstractTypeParamDecl *TPD) {
200+
for (auto Inherit: TPD->getInherited()) {
201+
if (doIt(Inherit))
202+
return true;
203+
}
200204
return false;
201205
}
202206

@@ -207,10 +211,6 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
207211
for (auto GP : NTD->getGenericParams()->getParams()) {
208212
if (doIt(GP))
209213
return true;
210-
for(auto Inherit: GP->getInherited()) {
211-
if (doIt(Inherit))
212-
return true;
213-
}
214214
}
215215
// Visit param conformance
216216
for (auto &Req : NTD->getGenericParams()->getRequirements()) {
@@ -266,10 +266,6 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
266266
for (auto &P : AFD->getGenericParams()->getParams()) {
267267
if (doIt(P))
268268
return true;
269-
for (auto Inherit : P->getInherited()) {
270-
if (doIt(Inherit))
271-
return true;
272-
}
273269
}
274270

275271
// Visit param conformance

test/Index/roles.swift

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,27 +127,18 @@ struct AStruct {
127127
}
128128
}
129129

130-
class AClass {
130+
class AClass { // used for references only
131131
var y: AStruct;
132132
var z: [Int]
133-
134133
init(x: Int) {
135134
y = AStruct(x: x)
136135
self.z = [1, 2, 3]
137136
}
138-
139137
subscript(index: Int) -> Int {
140-
get {
141-
return z[0]
142-
}
143-
set {
144-
z[0] = newValue
145-
}
146-
}
147-
148-
func foo() -> Int {
149-
return z[0]
138+
get { return z[0] }
139+
set { z[0] = newValue }
150140
}
141+
func foo() -> Int { return z[0] }
151142
}
152143

153144
let _ = AClass.foo
@@ -161,21 +152,38 @@ let _ = AClass(x: 1)[1] = 2
161152
// CHECK: [[@LINE-1]]:21 | instance-property/subscript/Swift | subscript(_:) | s:14swift_ide_test6AClassC9subscriptSiSici | Ref,Writ | rel: 0
162153
// CHECK: [[@LINE-2]]:21 | function/acc-set/Swift | setter:subscript(_:) | s:14swift_ide_test6AClassC9subscriptSiSicfs | Ref,Call,Dyn,Impl,RelRec | rel: 1
163154

155+
// RelationBaseOf, RelationOverrideOf
156+
157+
protocol X {}
158+
// CHECK: [[@LINE-1]]:10 | protocol/Swift | X | [[X_USR:.*]] | Def | rel: 0
159+
160+
class ImplementsX : X {}
161+
// CHECK: [[@LINE-1]]:7 | class/Swift | ImplementsX | [[ImplementsX_USR:.*]] | Def | rel: 0
162+
// CHECK: [[@LINE-2]]:21 | protocol/Swift | X | [[X_USR]] | Ref,RelBase | rel: 1
163+
// CHECK-NEXT: RelBase | ImplementsX | [[ImplementsX_USR]]
164+
164165
protocol AProtocol {
165166
// CHECK: [[@LINE-1]]:10 | protocol/Swift | AProtocol | [[AProtocol_USR:.*]] | Def | rel: 0
167+
168+
associatedtype T : X
169+
// CHECK: [[@LINE-1]]:18 | type-alias/associated-type/Swift | T | s:14swift_ide_test9AProtocolP1T | Def,RelChild | rel: 1
170+
// CHECK-NEXT: RelChild | AProtocol | [[AProtocol_USR]]
171+
// CHECK: [[@LINE-3]]:22 | protocol/Swift | X | [[X_USR]] | Ref | rel: 0
172+
166173
func foo() -> Int
167174
// CHECK: [[@LINE-1]]:8 | instance-method/Swift | foo() | s:14swift_ide_test9AProtocolP3fooSiyF | Def,RelChild | rel: 1
168175
// CHECK-NEXT: RelChild | AProtocol | s:14swift_ide_test9AProtocolP
169176
}
170177

171-
// RelationBaseOf, RelationOverrideOf
172178
class ASubClass : AClass, AProtocol {
173179
// CHECK: [[@LINE-1]]:7 | class/Swift | ASubClass | s:14swift_ide_test9ASubClassC | Def | rel: 0
174180
// CHECK: [[@LINE-2]]:19 | class/Swift | AClass | s:14swift_ide_test6AClassC | Ref,RelBase | rel: 1
175181
// CHECK-NEXT: RelBase | ASubClass | s:14swift_ide_test9ASubClassC
176182
// CHECK: [[@LINE-4]]:27 | protocol/Swift | AProtocol | s:14swift_ide_test9AProtocolP | Ref,RelBase | rel: 1
177183
// CHECK-NEXT: RelBase | ASubClass | s:14swift_ide_test9ASubClassC
178184

185+
typealias T = ImplementsX
186+
179187
override func foo() -> Int {
180188
// CHECK: [[@LINE-1]]:17 | instance-method/Swift | foo() | s:14swift_ide_test9ASubClassC3fooSiyF | Def,RelChild,RelOver | rel: 3
181189
// CHECK-NEXT: RelOver | foo() | s:14swift_ide_test6AClassC3fooSiyF
@@ -209,7 +217,9 @@ extension OuterS.InnerS : AProtocol {
209217
// CHECK: [[@LINE-4]]:27 | protocol/Swift | AProtocol | [[AProtocol_USR]] | Ref,RelBase | rel: 1
210218
// CHECK-NEXT: RelBase | InnerS | [[EXT_INNERS_USR]]
211219
// CHECK: [[@LINE-6]]:11 | struct/Swift | OuterS | [[OUTERS_USR]] | Ref | rel: 0
212-
func foo() {}
220+
221+
typealias T = ImplementsX
222+
func foo() -> Int { return 1 }
213223
}
214224

215225
var anInstance = AClass(x: 1)

0 commit comments

Comments
 (0)