Commit c17793b487

Veikka Tuominen <git@vexu.eu>
2022-08-16 15:37:27
Sema: ignore current declaration in ambiguous reference error
Closes #12429
1 parent b392228
Changed files (2)
src
test
behavior
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 => {
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);
+}