From c17793b4875cc9e1ccb605431142ffecb0b6f3f2 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Tue, 16 Aug 2022 16:37:27 +0300 Subject: [PATCH] Sema: ignore current declaration in ambiguous reference error Closes #12429 --- src/Sema.zig | 11 +++++++++++ test/behavior/basic.zig | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/Sema.zig b/src/Sema.zig index 879ecb4e2f..d7d6994bcd 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -5384,6 +5384,17 @@ fn lookupInNamespace( } } + { + var i: usize = 0; + while (i < candidates.items.len) { + if (candidates.items[i] == sema.owner_decl_index) { + _ = candidates.orderedRemove(i); + } else { + i += 1; + } + } + } + switch (candidates.items.len) { 0 => {}, 1 => { diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index 1a1412420a..4d8b176fbf 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -1104,3 +1104,24 @@ test "namespace lookup ignores decl causing the lookup" { }; _ = S.foo(); } + +test "ambiguous reference error ignores current declaration" { + const S = struct { + const foo = 666; + + const a = @This(); + const b = struct { + const foo = a.foo; + const bar = struct { + bar: u32 = b.foo, + }; + + comptime { + _ = b.foo; + } + }; + + usingnamespace b; + }; + try expect(S.b.foo == 666); +}