zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit eaa6b04c3cb8073d5a1510560ec8f1e433984895 (tree)
parent 0f820d0bdf98b3f8429a9cf2f1b405c2c0a4d958
Author: Veikka Tuominen <git@vexu.eu>
Date:   Fri, 10 Jun 2022 00:11:46 +0300

Sema: skip decl causing namespace lookup when doing lookup

Diffstat:
Msrc/Sema.zig | 2++
Mtest/behavior/basic.zig | 23+++++++++++++++++++++++
2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/src/Sema.zig b/src/Sema.zig @@ -4967,6 +4967,8 @@ fn lookupInNamespace( var it = check_ns.usingnamespace_set.iterator(); while (it.next()) |entry| { const sub_usingnamespace_decl_index = entry.key_ptr.*; + // Skip the decl we're currently analysing. + if (sub_usingnamespace_decl_index == sema.owner_decl_index) continue; const sub_usingnamespace_decl = mod.declPtr(sub_usingnamespace_decl_index); const sub_is_pub = entry.value_ptr.*; if (!sub_is_pub and src_file != sub_usingnamespace_decl.getFileScope()) { diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig @@ -1086,3 +1086,26 @@ test "inline call of function with a switch inside the return statement" { }; try expect(S.foo(1) == 1); } + +test "namespace lookup ignores decl causing the lookup" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO + + const S = struct { + fn Mixin(comptime T: type) type { + return struct { + fn foo() void { + const set = std.EnumSet(T.E).init(undefined); + _ = set; + } + }; + } + + const E = enum { a, b }; + usingnamespace Mixin(@This()); + }; + _ = S.foo(); +}