Skip to content

Commit c17793b

Browse files
committed
Sema: ignore current declaration in ambiguous reference error
Closes #12429
1 parent b392228 commit c17793b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/Sema.zig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,3 +1104,24 @@ test "namespace lookup ignores decl causing the lookup" {
11041104
};
11051105
_ = S.foo();
11061106
}
1107+
1108+
test "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+
}

0 commit comments

Comments
 (0)