Skip to content

Fix missing refs to accesor when shadowing with if-let shorthand. #80444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/Index/IndexSymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct IndexSymbol : IndexRelation {
SmallVector<IndexRelation, 3> Relations;
unsigned line = 0;
unsigned column = 0;
const Decl *originalDecl = nullptr;
ValueDecl *originalDecl = nullptr;

IndexSymbol() = default;

Expand Down
5 changes: 5 additions & 0 deletions lib/Index/Index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,11 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
// Dig back to the original captured variable
if (isa<VarDecl>(D)) {
Info.originalDecl = firstDecl(D);
// When indexing locals is disabled, the reference to the original decl
// would be lost without overwriting the local symbol.
if (!IdxConsumer.indexLocals()) {
D = Info.originalDecl;
}
}

if (Data.isImplicit)
Expand Down
8 changes: 4 additions & 4 deletions test/Index/index_shadow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct ShadowedTest {
if let shadowedVar {
// CHECK_LOCALS-NOT: [[@LINE+3]]:11 {{.*}} s:14swift_ide_test12ShadowedTestV11shadowedVarSiSgSgvp {{.*}}Ref
// CHECK_LOCALS: [[@LINE+2]]:11 {{.*}} s:14swift_ide_test12ShadowedTestV06shadowE0yyF11shadowedVarL_SiSgvp {{.*}}Ref
// CHECK-NOT: [[@LINE+1]]:11 {{.*}} shadowedVar {{.*}}Ref
// CHECK: [[@LINE+1]]:11 | instance-property/Swift | shadowedVar | s:14swift_ide_test12ShadowedTestV11shadowedVarSiSgSgvp {{.*}}Ref
_ = shadowedVar

// CHECK_LOCALS: [[@LINE+4]]:14 {{.*}} s:14swift_ide_test12ShadowedTestV11shadowedVarSiSgSgvp {{.*}}Ref
Expand All @@ -49,7 +49,7 @@ struct ShadowedTest {
// CHECK: [[@LINE+1]]:14 {{.*}} s:14swift_ide_test12ShadowedTestV11shadowedVarSiSgSgvp {{.*}}Ref
if let shadowedVar {
// CHECK_LOCALS: [[@LINE+2]]:13 {{.*}} s:14swift_ide_test12ShadowedTestV06shadowE0yyF11shadowedVarL0_Sivp {{.*}}Ref
// CHECK-NOT: [[@LINE+1]]:13 {{.*}} shadowedVar {{.*}}Ref
// CHECK: [[@LINE+1]]:13 | instance-property/Swift | shadowedVar | s:14swift_ide_test12ShadowedTestV11shadowedVarSiSgSgvp {{.*}}Ref
_ = shadowedVar
}
}
Expand All @@ -60,7 +60,7 @@ struct ShadowedTest {
// CHECK: [[@LINE+1]]:12 {{.*}} s:14swift_ide_test12ShadowedTestV11shadowedVarSiSgSgvp {{.*}}Ref
_ = { [shadowedVar] in
// CHECK_LOCALS: [[@LINE+2]]:11 {{.*}} s:14swift_ide_test12ShadowedTestV06shadowE0yyF11shadowedVarL1_SiSgSgvp {{.*}}Ref
// CHECK-NOT: [[@LINE+1]]:11 {{.*}} shadowedVar {{.*}}Ref
// CHECK: [[@LINE+1]]:11 | instance-property/Swift | shadowedVar | s:14swift_ide_test12ShadowedTestV11shadowedVarSiSgSgvp {{.*}}Ref
_ = shadowedVar

// CHECK_LOCALS: [[@LINE+4]]:14 {{.*}} s:14swift_ide_test12ShadowedTestV11shadowedVarSiSgSgvp {{.*}}Ref
Expand All @@ -69,7 +69,7 @@ struct ShadowedTest {
// CHECK: [[@LINE+1]]:14 {{.*}} s:14swift_ide_test12ShadowedTestV11shadowedVarSiSgSgvp {{.*}}Ref
_ = { [shadowedVar] in
// CHECK_LOCALS: [[@LINE+2]]:13 {{.*}} s:14swift_ide_test12ShadowedTestV06shadowE0yyFyycfU_11shadowedVarL_SiSgSgvp {{.*}}Ref
// CHECK-NOT: [[@LINE+1]]:13 {{.*}} shadowedVar {{.*}}Ref
// CHECK: [[@LINE+1]]:13 | instance-property/Swift | shadowedVar | s:14swift_ide_test12ShadowedTestV11shadowedVarSiSgSgvp {{.*}}Ref
_ = shadowedVar
}
}
Expand Down