@@ -361,7 +361,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
361
361
bool initIndexSymbol (ValueDecl *D, SourceLoc Loc, bool IsRef,
362
362
IndexSymbol &Info);
363
363
bool initFuncDeclIndexSymbol (ValueDecl *D, IndexSymbol &Info);
364
- bool initCallRefIndexSymbol (Expr *CurrentE, Expr *ParentE, ValueDecl *D,
364
+ bool initFuncRefIndexSymbol (Expr *CurrentE, Expr *ParentE, ValueDecl *D,
365
365
SourceLoc Loc, IndexSymbol &Info);
366
366
bool initVarRefIndexSymbols (Expr *CurrentE, ValueDecl *D, SourceLoc Loc,
367
367
IndexSymbol &Info);
@@ -662,15 +662,15 @@ bool IndexSwiftASTWalker::reportPseudoAccessor(AbstractStorageDecl *D,
662
662
if (IsRef) {
663
663
IndexSymbol Info;
664
664
665
- // initCallRefIndexSymbol uses the top of the entities stack as the caller,
665
+ // initFuncRefIndexSymbol uses the top of the entities stack as the caller,
666
666
// but in this case the top of the stack is the referenced
667
667
// AbstractStorageDecl.
668
668
assert (getParentDecl () == D);
669
669
auto PreviousTop = EntitiesStack.pop_back_val ();
670
- bool initCallFailed = initCallRefIndexSymbol (ExprStack. back (), getParentExpr (), D, Loc, Info);
670
+ bool initFailed = initFuncRefIndexSymbol ( getCurrentExpr (), getParentExpr (), D, Loc, Info);
671
671
EntitiesStack.push_back (PreviousTop);
672
672
673
- if (initCallFailed )
673
+ if (initFailed )
674
674
return true ; // continue walking.
675
675
if (updateInfo (Info))
676
676
return true ;
@@ -793,7 +793,7 @@ bool IndexSwiftASTWalker::reportRef(ValueDecl *D, SourceLoc Loc,
793
793
return true ; // keep walking
794
794
795
795
if (isa<AbstractFunctionDecl>(D)) {
796
- if (initCallRefIndexSymbol (getCurrentExpr (), getParentExpr (), D, Loc, Info))
796
+ if (initFuncRefIndexSymbol (getCurrentExpr (), getParentExpr (), D, Loc, Info))
797
797
return true ;
798
798
} else if (isa<AbstractStorageDecl>(D)) {
799
799
if (initVarRefIndexSymbols (getCurrentExpr (), D, Loc, Info))
@@ -809,11 +809,10 @@ bool IndexSwiftASTWalker::reportRef(ValueDecl *D, SourceLoc Loc,
809
809
}
810
810
811
811
// Report the accessors that were utilized.
812
- if (isa <AbstractStorageDecl>(D)) {
812
+ if (AbstractStorageDecl *ASD = dyn_cast <AbstractStorageDecl>(D)) {
813
813
bool UsesGetter = Info.roles & (SymbolRoleSet)SymbolRole::Read;
814
814
bool UsesSetter = Info.roles & (SymbolRoleSet)SymbolRole::Write;
815
815
816
- AbstractStorageDecl *ASD = cast<AbstractStorageDecl>(D);
817
816
if (UsesGetter)
818
817
if (!reportPseudoAccessor (ASD, AccessorKind::IsGetter, /* IsRef=*/ true ,
819
818
Loc))
@@ -947,15 +946,23 @@ static bool isDynamicCall(Expr *BaseE, ValueDecl *D) {
947
946
return true ;
948
947
}
949
948
950
- bool IndexSwiftASTWalker::initCallRefIndexSymbol (Expr *CurrentE, Expr *ParentE,
949
+ bool IndexSwiftASTWalker::initFuncRefIndexSymbol (Expr *CurrentE, Expr *ParentE,
951
950
ValueDecl *D, SourceLoc Loc,
952
951
IndexSymbol &Info) {
953
- if (!ParentE)
954
- return true ;
955
952
956
953
if (initIndexSymbol (D, Loc, /* IsRef=*/ true , Info))
957
954
return true ;
958
955
956
+ if (!CurrentE)
957
+ return false ;
958
+
959
+ // FIXME: the below check maintains existing indexing behaviour with
960
+ // pseudo/accessor output but seems incorrect. E.g otherGlobal in:
961
+ // let global = otherGlobal
962
+ // will not have a parent expression so no accessor call is reported
963
+ if (!ParentE)
964
+ return true ;
965
+
959
966
Info.roles |= (unsigned )SymbolRole::Call;
960
967
961
968
Decl *ParentD = getParentDecl ();
@@ -995,10 +1002,13 @@ bool IndexSwiftASTWalker::initCallRefIndexSymbol(Expr *CurrentE, Expr *ParentE,
995
1002
996
1003
bool IndexSwiftASTWalker::initVarRefIndexSymbols (Expr *CurrentE, ValueDecl *D, SourceLoc Loc, IndexSymbol &Info) {
997
1004
998
- if (!(CurrentE-> getReferencedDecl () == D ))
1005
+ if (initIndexSymbol (D, Loc, /* IsRef= */ true , Info ))
999
1006
return true ;
1000
1007
1001
- if (initIndexSymbol (D, Loc, /* IsRef=*/ true , Info))
1008
+ if (!CurrentE)
1009
+ return false ;
1010
+
1011
+ if (!(CurrentE->getReferencedDecl () == D))
1002
1012
return true ;
1003
1013
1004
1014
AccessKind Kind = CurrentE->hasLValueAccessKind () ? CurrentE->getLValueAccessKind () : AccessKind::Read;
0 commit comments