authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-20 23:13:02-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-20 23:13:02-04:00
log140dc2f43e347ddddc2f6f344b388bdc74c97c56
tree56d3443400f4f2a11c975607d1146127a62575ca
parent688aa114e434e05b96f916c168f177aa0484baec

stage1: fix false positive redeclared variable compile error


2 files changed, 30 insertions(+), 6 deletions(-)

src/analyze.cpp+18-3
......@@ -3612,6 +3612,12 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {
36123612 auto entry = decls_scope->decl_table.put_unique(tld->name, tld);
36133613 if (entry) {
36143614 Tld *other_tld = entry->value;
3615 if (other_tld->id == TldIdVar) {
3616 ZigVar *var = reinterpret_cast<TldVar *>(other_tld)->var;
3617 if (var->var_type != nullptr && type_is_invalid(var->var_type)) {
3618 return; // already reported compile error
3619 }
3620 }
36153621 ErrorMsg *msg = add_node_error(g, tld->source_node, buf_sprintf("redefinition of '%s'", buf_ptr(tld->name)));
36163622 add_error_note(g, msg, other_tld->source_node, buf_sprintf("previous definition is here"));
36173623 return;
......@@ -3887,9 +3893,18 @@ ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf
38873893 if (search_scope != nullptr) {
38883894 Tld *tld = find_decl(g, search_scope, name);
38893895 if (tld != nullptr && tld != src_tld) {
3890 ErrorMsg *msg = add_node_error(g, source_node,
3891 buf_sprintf("redefinition of '%s'", buf_ptr(name)));
3892 add_error_note(g, msg, tld->source_node, buf_sprintf("previous definition is here"));
3896 bool want_err_msg = true;
3897 if (tld->id == TldIdVar) {
3898 ZigVar *var = reinterpret_cast<TldVar *>(tld)->var;
3899 if (var->var_type != nullptr && type_is_invalid(var->var_type)) {
3900 want_err_msg = false;
3901 }
3902 }
3903 if (want_err_msg) {
3904 ErrorMsg *msg = add_node_error(g, source_node,
3905 buf_sprintf("redefinition of '%s'", buf_ptr(name)));
3906 add_error_note(g, msg, tld->source_node, buf_sprintf("previous definition is here"));
3907 }
38933908 variable_entry->var_type = g->builtin_types.entry_invalid;
38943909 }
38953910 }
src/ir.cpp+12-3
......@@ -5300,9 +5300,18 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s
53005300 } else {
53015301 Tld *tld = find_decl(codegen, parent_scope, name);
53025302 if (tld != nullptr) {
5303 ErrorMsg *msg = add_node_error(codegen, node,
5304 buf_sprintf("redefinition of '%s'", buf_ptr(name)));
5305 add_error_note(codegen, msg, tld->source_node, buf_sprintf("previous definition is here"));
5303 bool want_err_msg = true;
5304 if (tld->id == TldIdVar) {
5305 ZigVar *var = reinterpret_cast<TldVar *>(tld)->var;
5306 if (var->var_type != nullptr && type_is_invalid(var->var_type)) {
5307 want_err_msg = false;
5308 }
5309 }
5310 if (want_err_msg) {
5311 ErrorMsg *msg = add_node_error(codegen, node,
5312 buf_sprintf("redefinition of '%s'", buf_ptr(name)));
5313 add_error_note(codegen, msg, tld->source_node, buf_sprintf("previous definition is here"));
5314 }
53065315 variable_entry->var_type = codegen->builtin_types.entry_invalid;
53075316 }
53085317 }