Skip to content

Commit df8efc2

Browse files
author
Nathan Hawes
authored
Merge pull request #7846 from nathawes/rdar25616751
[indexer] Fix missing references for inherits of associated types
2 parents 2423045 + 85805f3 commit df8efc2

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
@@ -134,27 +134,18 @@ struct AStruct {
134134
}
135135
}
136136

137-
class AClass {
137+
class AClass { // used for references only
138138
var y: AStruct;
139139
var z: [Int]
140-
141140
init(x: Int) {
142141
y = AStruct(x: x)
143142
self.z = [1, 2, 3]
144143
}
145-
146144
subscript(index: Int) -> Int {
147-
get {
148-
return z[0]
149-
}
150-
set {
151-
z[0] = newValue
152-
}
153-
}
154-
155-
func foo() -> Int {
156-
return z[0]
145+
get { return z[0] }
146+
set { z[0] = newValue }
157147
}
148+
func foo() -> Int { return z[0] }
158149
}
159150

160151
let _ = AClass.foo
@@ -168,21 +159,38 @@ let _ = AClass(x: 1)[1] = 2
168159
// CHECK: [[@LINE-1]]:21 | instance-property/subscript/Swift | subscript(_:) | s:14swift_ide_test6AClassC9subscriptSiSici | Ref,Writ | rel: 0
169160
// CHECK: [[@LINE-2]]:21 | function/acc-set/Swift | setter:subscript(_:) | s:14swift_ide_test6AClassC9subscriptSiSicfs | Ref,Call,Dyn,Impl,RelRec | rel: 1
170161

162+
// RelationBaseOf, RelationOverrideOf
163+
164+
protocol X {}
165+
// CHECK: [[@LINE-1]]:10 | protocol/Swift | X | [[X_USR:.*]] | Def | rel: 0
166+
167+
class ImplementsX : X {}
168+
// CHECK: [[@LINE-1]]:7 | class/Swift | ImplementsX | [[ImplementsX_USR:.*]] | Def | rel: 0
169+
// CHECK: [[@LINE-2]]:21 | protocol/Swift | X | [[X_USR]] | Ref,RelBase | rel: 1
170+
// CHECK-NEXT: RelBase | ImplementsX | [[ImplementsX_USR]]
171+
171172
protocol AProtocol {
172173
// CHECK: [[@LINE-1]]:10 | protocol/Swift | AProtocol | [[AProtocol_USR:.*]] | Def | rel: 0
174+
175+
associatedtype T : X
176+
// CHECK: [[@LINE-1]]:18 | type-alias/associated-type/Swift | T | s:14swift_ide_test9AProtocolP1T | Def,RelChild | rel: 1
177+
// CHECK-NEXT: RelChild | AProtocol | [[AProtocol_USR]]
178+
// CHECK: [[@LINE-3]]:22 | protocol/Swift | X | [[X_USR]] | Ref | rel: 0
179+
173180
func foo() -> Int
174181
// CHECK: [[@LINE-1]]:8 | instance-method/Swift | foo() | s:14swift_ide_test9AProtocolP3fooSiyF | Def,RelChild | rel: 1
175182
// CHECK-NEXT: RelChild | AProtocol | s:14swift_ide_test9AProtocolP
176183
}
177184

178-
// RelationBaseOf, RelationOverrideOf
179185
class ASubClass : AClass, AProtocol {
180186
// CHECK: [[@LINE-1]]:7 | class/Swift | ASubClass | s:14swift_ide_test9ASubClassC | Def | rel: 0
181187
// CHECK: [[@LINE-2]]:19 | class/Swift | AClass | s:14swift_ide_test6AClassC | Ref,RelBase | rel: 1
182188
// CHECK-NEXT: RelBase | ASubClass | s:14swift_ide_test9ASubClassC
183189
// CHECK: [[@LINE-4]]:27 | protocol/Swift | AProtocol | s:14swift_ide_test9AProtocolP | Ref,RelBase | rel: 1
184190
// CHECK-NEXT: RelBase | ASubClass | s:14swift_ide_test9ASubClassC
185191

192+
typealias T = ImplementsX
193+
186194
override func foo() -> Int {
187195
// CHECK: [[@LINE-1]]:17 | instance-method/Swift | foo() | s:14swift_ide_test9ASubClassC3fooSiyF | Def,RelChild,RelOver | rel: 3
188196
// CHECK-NEXT: RelOver | foo() | s:14swift_ide_test6AClassC3fooSiyF
@@ -216,7 +224,9 @@ extension OuterS.InnerS : AProtocol {
216224
// CHECK: [[@LINE-4]]:27 | protocol/Swift | AProtocol | [[AProtocol_USR]] | Ref,RelBase | rel: 1
217225
// CHECK-NEXT: RelBase | InnerS | [[EXT_INNERS_USR]]
218226
// CHECK: [[@LINE-6]]:11 | struct/Swift | OuterS | [[OUTERS_USR]] | Ref | rel: 0
219-
func foo() {}
227+
228+
typealias T = ImplementsX
229+
func foo() -> Int { return 1 }
220230
}
221231

222232
var anInstance = AClass(x: 1)

0 commit comments

Comments
 (0)