diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-05-20 23:13:02 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-05-20 23:13:02 -0400 |
| commit | 140dc2f43e347ddddc2f6f344b388bdc74c97c56 (patch) | |
| tree | 56d3443400f4f2a11c975607d1146127a62575ca /src/analyze.cpp | |
| parent | 688aa114e434e05b96f916c168f177aa0484baec (diff) | |
| download | zig-140dc2f43e347ddddc2f6f344b388bdc74c97c56.tar.gz zig-140dc2f43e347ddddc2f6f344b388bdc74c97c56.zip | |
stage1: fix false positive redeclared variable compile error
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 5a2629a0ea..0fddc568a5 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -3612,6 +3612,12 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) { auto entry = decls_scope->decl_table.put_unique(tld->name, tld); if (entry) { Tld *other_tld = entry->value; + if (other_tld->id == TldIdVar) { + ZigVar *var = reinterpret_cast<TldVar *>(other_tld)->var; + if (var->var_type != nullptr && type_is_invalid(var->var_type)) { + return; // already reported compile error + } + } ErrorMsg *msg = add_node_error(g, tld->source_node, buf_sprintf("redefinition of '%s'", buf_ptr(tld->name))); add_error_note(g, msg, other_tld->source_node, buf_sprintf("previous definition is here")); return; @@ -3887,9 +3893,18 @@ 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 && 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")); + bool want_err_msg = true; + if (tld->id == TldIdVar) { + ZigVar *var = reinterpret_cast<TldVar *>(tld)->var; + if (var->var_type != nullptr && type_is_invalid(var->var_type)) { + want_err_msg = false; + } + } + if (want_err_msg) { + 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")); + } variable_entry->var_type = g->builtin_types.entry_invalid; } } |
