Skip to content

Commit 76b57d5

Browse files
committed
[IDE] Remove invalid assertions
The declaration and reference aren't necessarily the same type (eg. they could be a function and a local). Thus they don't have to have the same names, making the assertion invalid. Resolves #63262. (cherry picked from commit 21f997c)
1 parent 3d6fc7d commit 76b57d5

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/IDE/IDETypeChecking.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -942,8 +942,6 @@ swift::getShorthandShadows(CaptureListExpr *CaptureList, DeclContext *DC) {
942942
if (!ReferencedVar)
943943
continue;
944944

945-
assert(DeclaredVar->getName() == ReferencedVar->getName());
946-
947945
Result.emplace_back(std::make_pair(DeclaredVar, ReferencedVar));
948946
}
949947
return Result;
@@ -970,7 +968,6 @@ swift::getShorthandShadows(LabeledConditionalStmt *CondStmt, DeclContext *DC) {
970968
Cond.getPattern()->forEachVariable([&](VarDecl *DeclaredVar) {
971969
if (DeclaredVar->getLoc() != Init->getLoc())
972970
return;
973-
assert(DeclaredVar->getName() == ReferencedVar->getName());
974971
Result.emplace_back(std::make_pair(DeclaredVar, ReferencedVar));
975972
});
976973
}

test/Index/index_shadow.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// The index will output references to the shadowed-declaration rather than
55
// the one defined by the shorthand if-let or capture. It also skips
66
// outputting the shadowing-definiiton since it would then have no references.
7-
87
struct ShadowedTest {
98
// CHECK: [[@LINE+1]]:7 {{.*}} s:14swift_ide_test12ShadowedTestV11shadowedVarSiSgSgvp {{.*}}Def
109
let shadowedVar: Int?? = 1
@@ -57,4 +56,16 @@ struct ShadowedTest {
5756
}
5857
}
5958
}
59+
60+
func nestedFuncTest() {
61+
// CHECK: [[@LINE+1]]:10 {{.*}} s:14swift_ide_test12ShadowedTestV010nestedFuncE0yyF08shadowedG0L_yyF {{.*}}Def
62+
func shadowedFunc() {
63+
// CHECK-NOT: [[@LINE+2]]:14 {{.*}} shadowedFunc {{.*}}Def
64+
// CHECK: [[@LINE+1]]:14 {{.*}} s:14swift_ide_test12ShadowedTestV010nestedFuncE0yyF08shadowedG0L_yyF {{.*}}Ref
65+
_ = { [shadowedFunc] in
66+
// CHECK: [[@LINE+1]]:13 {{.*}} s:14swift_ide_test12ShadowedTestV010nestedFuncE0yyF08shadowedG0L_yyF {{.*}}Ref
67+
_ = shadowedFunc
68+
}
69+
}
70+
}
6071
}

0 commit comments

Comments
 (0)