From 2c8864f634cbb42bf45f4f6b7109e9129b357247 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Thu, 26 Sep 2019 17:54:45 +0200 Subject: [PATCH] Don't warn about redeclaration for the same var node Closes #3316 --- src/analyze.cpp | 2 +- test/stage1/behavior/usingnamespace.zig | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/analyze.cpp b/src/analyze.cpp index 5a3551a7c2..bdb007a68a 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -3676,7 +3676,7 @@ ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf } if (search_scope != nullptr) { Tld *tld = find_decl(g, search_scope, name); - if (tld != nullptr) { + if (tld != nullptr && tld != src_tld) { ErrorMsg *msg = add_node_error(g, source_node, buf_sprintf("redefinition of '%s'", buf_ptr(name))); add_error_note(g, msg, tld->source_node, buf_sprintf("previous definition is here")); diff --git a/test/stage1/behavior/usingnamespace.zig b/test/stage1/behavior/usingnamespace.zig index fb45a9392d..a44bf1bbc3 100644 --- a/test/stage1/behavior/usingnamespace.zig +++ b/test/stage1/behavior/usingnamespace.zig @@ -12,3 +12,11 @@ test "usingnamespace inside a generic struct" { std2.testing.expect(true); testing2.expect(true); } + +usingnamespace struct { + pub const foo = 42; +}; + +test "usingnamespace does not redeclare an imported variable" { + comptime std.testing.expect(foo == 42); +}