Skip to content

Commit 5c3bd1d

Browse files
author
Nathan Hawes
authored
Merge pull request #9184 from nathawes/index-param-fix
[indexer] Don't index closure params.
2 parents 719c8ff + 9abeb0d commit 5c3bd1d

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

lib/Index/Index.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
378378
return true;
379379
}
380380

381-
Decl *getParentDecl() {
381+
Decl *getParentDecl() const {
382382
if (!EntitiesStack.empty())
383383
return EntitiesStack.back().D;
384384
return nullptr;
@@ -390,25 +390,25 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
390390
EntitiesStack.back().RefsToSuppress.push_back(Loc);
391391
}
392392

393-
bool isRepressed(SourceLoc Loc) {
393+
bool isRepressed(SourceLoc Loc) const {
394394
if (EntitiesStack.empty() || Loc.isInvalid())
395395
return false;
396396
auto &Suppressed = EntitiesStack.back().RefsToSuppress;
397397
return std::find(Suppressed.begin(), Suppressed.end(), Loc) != Suppressed.end();
398398

399399
}
400400

401-
Expr *getContainingExpr(size_t index) {
401+
Expr *getContainingExpr(size_t index) const {
402402
if (ExprStack.size() > index)
403403
return ExprStack.end()[-(index + 1)];
404404
return nullptr;
405405
}
406406

407-
Expr *getCurrentExpr() {
407+
Expr *getCurrentExpr() const {
408408
return ExprStack.empty() ? nullptr : ExprStack.back();
409409
}
410410

411-
Expr *getParentExpr() {
411+
Expr *getParentExpr() const {
412412
return getContainingExpr(1);
413413
}
414414

@@ -466,8 +466,11 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
466466
bool shouldIndex(ValueDecl *D, bool IsRef) const {
467467
if (D->isImplicit() && !isa<ConstructorDecl>(D))
468468
return false;
469-
if (!IdxConsumer.indexLocals() && isLocalSymbol(D) && (!isa<ParamDecl>(D) || IsRef))
470-
return false;
469+
470+
if (!IdxConsumer.indexLocals() && isLocalSymbol(D))
471+
return isa<ParamDecl>(D) && !IsRef &&
472+
D->getDeclContext()->getContextKind() != DeclContextKind::AbstractClosureExpr;
473+
471474
if (D->isPrivateStdlibDecl())
472475
return false;
473476

lib/Index/IndexSymbol.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,5 +232,6 @@ SymbolSubKind index::getSubKindForAccessor(AccessorKind AK) {
232232

233233
bool index::isLocalSymbol(const swift::Decl *D) {
234234
return D->getDeclContext()->getLocalContext() &&
235-
(!isa<ParamDecl>(D) || cast<ParamDecl>(D)->getArgumentNameLoc().isValid());
235+
(!isa<ParamDecl>(D) || cast<ParamDecl>(D)->getArgumentNameLoc().isValid() ||
236+
D->getDeclContext()->getContextKind() == DeclContextKind::AbstractClosureExpr);
236237
}

test/Index/roles.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ func aCalledFunction(a: Int, b: inout Int) {
7474
// CHECK-NEXT: RelCont | function/Swift | aCalledFunction(a:b:) | s:14swift_ide_test15aCalledFunctionySi1a_Siz1btF
7575
// CHECK: [[@LINE-3]]:7 | param/Swift | a | s:{{.*}} | Ref,Read,RelCont | rel: 1
7676
// CHECK-NEXT: RelCont | function/Swift | aCalledFunction(a:b:) | s:14swift_ide_test15aCalledFunctionySi1a_Siz1btF
77+
78+
_ = { ignored in ignored + 1}
79+
// CHECK-NOT: [[@LINE-1]]:9 {{.*}} | ignored | {{.*}}
80+
7781
}
7882

7983
aCalledFunction(a: 1, b: &z)

0 commit comments

Comments
 (0)