Skip to content

Commit 3140d85

Browse files
author
Nathan Hawes
committed
[index] Add missing parameter and return type references in subscript declarations
Resolves rdar://problem/32314185.
1 parent 6d5e8db commit 3140d85

File tree

2 files changed

+15
-30
lines changed

2 files changed

+15
-30
lines changed

lib/Index/Index.cpp

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -263,25 +263,6 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
263263
if (auto *VD = dyn_cast<ValueDecl>(D)) {
264264
if (!report(VD))
265265
return false;
266-
if (auto *SD = dyn_cast<SubscriptDecl>(VD)) {
267-
// Avoid indexing the indices, only walk the getter/setter.
268-
if (SD->getGetter())
269-
if (SourceEntityWalker::walk(cast<Decl>(SD->getGetter())))
270-
return false;
271-
if (SD->getSetter())
272-
if (SourceEntityWalker::walk(cast<Decl>(SD->getSetter())))
273-
return false;
274-
if (SD->hasAddressors()) {
275-
if (auto FD = SD->getAddressor())
276-
SourceEntityWalker::walk(cast<Decl>(FD));
277-
if (Cancelled)
278-
return false;
279-
if (auto FD = SD->getMutableAddressor())
280-
SourceEntityWalker::walk(cast<Decl>(FD));
281-
}
282-
walkToDeclPost(D);
283-
return false; // already walked what we needed.
284-
}
285266
}
286267
if (auto *ED = dyn_cast<ExtensionDecl>(D))
287268
return reportExtension(ED);
@@ -885,12 +866,13 @@ bool IndexSwiftASTWalker::reportExtension(ExtensionDecl *D) {
885866
bool IndexSwiftASTWalker::report(ValueDecl *D) {
886867
if (startEntityDecl(D)) {
887868
// Pass accessors.
888-
if (auto VarD = dyn_cast<VarDecl>(D)) {
869+
if (auto StoreD = dyn_cast<AbstractStorageDecl>(D)) {
889870
auto isNullOrImplicit = [](const Decl *D) -> bool {
890871
return !D || D->isImplicit();
891872
};
892-
if (isNullOrImplicit(VarD->getGetter()) &&
893-
isNullOrImplicit(VarD->getSetter())) {
873+
if (isa<VarDecl>(D) && isNullOrImplicit(StoreD->getGetter()) &&
874+
isNullOrImplicit(StoreD->getSetter())) {
875+
auto VarD = cast<VarDecl>(D);
894876
// No actual getter or setter, pass 'pseudo' accessors.
895877
// We create accessor entities so we can implement the functionality
896878
// of libclang, which reports implicit method property accessor
@@ -903,31 +885,31 @@ bool IndexSwiftASTWalker::report(ValueDecl *D) {
903885
if (!reportPseudoSetterDecl(VarD))
904886
return false;
905887
} else {
906-
if (auto FD = VarD->getGetter())
888+
if (auto FD = StoreD->getGetter())
907889
SourceEntityWalker::walk(cast<Decl>(FD));
908890
if (Cancelled)
909891
return false;
910-
if (auto FD = VarD->getSetter())
892+
if (auto FD = StoreD->getSetter())
911893
SourceEntityWalker::walk(cast<Decl>(FD));
912894
if (Cancelled)
913895
return false;
914896
}
915-
if (VarD->hasObservers()) {
916-
if (auto FD = VarD->getWillSetFunc())
897+
if (StoreD->hasObservers()) {
898+
if (auto FD = StoreD->getWillSetFunc())
917899
SourceEntityWalker::walk(cast<Decl>(FD));
918900
if (Cancelled)
919901
return false;
920-
if (auto FD = VarD->getDidSetFunc())
902+
if (auto FD = StoreD->getDidSetFunc())
921903
SourceEntityWalker::walk(cast<Decl>(FD));
922904
if (Cancelled)
923905
return false;
924906
}
925-
if (VarD->hasAddressors()) {
926-
if (auto FD = VarD->getAddressor())
907+
if (StoreD->hasAddressors()) {
908+
if (auto FD = StoreD->getAddressor())
927909
SourceEntityWalker::walk(cast<Decl>(FD));
928910
if (Cancelled)
929911
return false;
930-
if (auto FD = VarD->getMutableAddressor())
912+
if (auto FD = StoreD->getMutableAddressor())
931913
SourceEntityWalker::walk(cast<Decl>(FD));
932914
}
933915
} else if (auto NTD = dyn_cast<NominalTypeDecl>(D)) {

test/Index/kinds.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ struct AStruct {
3737
return base
3838
}
3939
}
40+
// CHECK: [[@LINE-20]]:13 | param/Swift | index | {{.*}} | Def,RelChild | rel: 1
41+
// CHECK: [[@LINE-21]]:20 | struct/Swift | Int | {{.*}} | Ref | rel: 0
42+
// CHECK: [[@LINE-22]]:28 | struct/Swift | Int | {{.*}} | Ref | rel: 0
4043
}
4144

4245
// Class

0 commit comments

Comments
 (0)