authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-16 16:37:27+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-16 16:37:27+03:00
logc17793b4875cc9e1ccb605431142ffecb0b6f3f2
treec2304b0cb0458e8ea78e6a7575a414f84a071ea6
parentb3922289be1ffaf194b55face332892280981356

Sema: ignore current declaration in ambiguous reference error

Closes #12429

2 files changed, 32 insertions(+), 0 deletions(-)

src/Sema.zig+11
......@@ -5384,6 +5384,17 @@ fn lookupInNamespace(
53845384 }
53855385 }
53865386
5387 {
5388 var i: usize = 0;
5389 while (i < candidates.items.len) {
5390 if (candidates.items[i] == sema.owner_decl_index) {
5391 _ = candidates.orderedRemove(i);
5392 } else {
5393 i += 1;
5394 }
5395 }
5396 }
5397
53875398 switch (candidates.items.len) {
53885399 0 => {},
53895400 1 => {
test/behavior/basic.zig+21
......@@ -1104,3 +1104,24 @@ test "namespace lookup ignores decl causing the lookup" {
11041104 };
11051105 _ = S.foo();
11061106}
1107
1108test "ambiguous reference error ignores current declaration" {
1109 const S = struct {
1110 const foo = 666;
1111
1112 const a = @This();
1113 const b = struct {
1114 const foo = a.foo;
1115 const bar = struct {
1116 bar: u32 = b.foo,
1117 };
1118
1119 comptime {
1120 _ = b.foo;
1121 }
1122 };
1123
1124 usingnamespace b;
1125 };
1126 try expect(S.b.foo == 666);
1127}