@@ -151,6 +151,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
151
151
};
152
152
SmallVector<Entity, 6 > EntitiesStack;
153
153
SmallVector<Expr *, 8 > ExprStack;
154
+ SmallVector<const AccessorDecl *, 4 > ManuallyVisitedAccessorStack;
154
155
bool Cancelled = false ;
155
156
156
157
struct NameAndUSR {
@@ -253,7 +254,10 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
253
254
: IdxConsumer(IdxConsumer), SrcMgr(Ctx.SourceMgr), BufferID(BufferID),
254
255
enableWarnings (IdxConsumer.enableWarnings()) {}
255
256
256
- ~IndexSwiftASTWalker () override { assert (Cancelled || EntitiesStack.empty ()); }
257
+ ~IndexSwiftASTWalker () override {
258
+ assert (Cancelled || EntitiesStack.empty ());
259
+ assert (Cancelled || ManuallyVisitedAccessorStack.empty ());
260
+ }
257
261
258
262
void visitModule (ModuleDecl &Mod, StringRef Hash);
259
263
void visitDeclContext (DeclContext *DC);
@@ -270,8 +274,8 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
270
274
if (AvailableAttr::isUnavailable (D))
271
275
return false ;
272
276
if (auto *AD = dyn_cast<AccessorDecl>(D)) {
273
- auto *Parent = getParentDecl ();
274
- if (Parent && Parent != AD-> getStorage () )
277
+ if (ManuallyVisitedAccessorStack. empty () ||
278
+ ManuallyVisitedAccessorStack. back () != AD)
275
279
return false ; // already handled as part of the var decl.
276
280
}
277
281
if (auto *VD = dyn_cast<ValueDecl>(D)) {
@@ -511,7 +515,12 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
511
515
void IndexSwiftASTWalker::visitDeclContext (DeclContext *Context) {
512
516
IsModuleFile = false ;
513
517
isSystemModule = Context->getParentModule ()->isSystemModule ();
518
+ auto accessor = dyn_cast<AccessorDecl>(Context);
519
+ if (accessor)
520
+ ManuallyVisitedAccessorStack.push_back (accessor);
514
521
walk (Context);
522
+ if (accessor)
523
+ ManuallyVisitedAccessorStack.pop_back ();
515
524
}
516
525
517
526
void IndexSwiftASTWalker::visitModule (ModuleDecl &Mod, StringRef KnownHash) {
@@ -957,14 +966,30 @@ bool IndexSwiftASTWalker::report(ValueDecl *D) {
957
966
accessor->getAccessorKind () == AccessorKind::Set))
958
967
continue ;
959
968
969
+ ManuallyVisitedAccessorStack.push_back (accessor);
960
970
SourceEntityWalker::walk (cast<Decl>(accessor));
971
+ ManuallyVisitedAccessorStack.pop_back ();
961
972
if (Cancelled)
962
973
return false ;
963
974
}
964
975
} else if (auto NTD = dyn_cast<NominalTypeDecl>(D)) {
965
976
if (!reportInheritedTypeRefs (NTD->getInherited (), NTD))
966
977
return false ;
967
978
}
979
+ } else {
980
+ // Even if we don't record a local property we still need to walk its
981
+ // accessor bodies.
982
+ if (auto StoreD = dyn_cast<AbstractStorageDecl>(D)) {
983
+ for (auto accessor : StoreD->getAllAccessors ()) {
984
+ if (accessor->isImplicit ())
985
+ continue ;
986
+ ManuallyVisitedAccessorStack.push_back (accessor);
987
+ SourceEntityWalker::walk (cast<Decl>(accessor));
988
+ ManuallyVisitedAccessorStack.pop_back ();
989
+ if (Cancelled)
990
+ return false ;
991
+ }
992
+ }
968
993
}
969
994
970
995
return !Cancelled;
0 commit comments