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) {...@@ -3612,6 +3612,12 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {
3612 auto entry = decls_scope->decl_table.put_unique(tld->name, tld);3612 auto entry = decls_scope->decl_table.put_unique(tld->name, tld);
3613 if (entry) {3613 if (entry) {
3614 Tld *other_tld = entry->value;3614 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 }
3615 ErrorMsg *msg = add_node_error(g, tld->source_node, buf_sprintf("redefinition of '%s'", buf_ptr(tld->name)));3621 ErrorMsg *msg = add_node_error(g, tld->source_node, buf_sprintf("redefinition of '%s'", buf_ptr(tld->name)));
3616 add_error_note(g, msg, other_tld->source_node, buf_sprintf("previous definition is here"));3622 add_error_note(g, msg, other_tld->source_node, buf_sprintf("previous definition is here"));
3617 return;3623 return;
...@@ -3887,9 +3893,18 @@ ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf...@@ -3887,9 +3893,18 @@ ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf
3887 if (search_scope != nullptr) {3893 if (search_scope != nullptr) {
3888 Tld *tld = find_decl(g, search_scope, name);3894 Tld *tld = find_decl(g, search_scope, name);
3889 if (tld != nullptr && tld != src_tld) {3895 if (tld != nullptr && tld != src_tld) {
3890 ErrorMsg *msg = add_node_error(g, source_node,3896 bool want_err_msg = true;
3891 buf_sprintf("redefinition of '%s'", buf_ptr(name)));3897 if (tld->id == TldIdVar) {
3892 add_error_note(g, msg, tld->source_node, buf_sprintf("previous definition is here"));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 }
3893 variable_entry->var_type = g->builtin_types.entry_invalid;3908 variable_entry->var_type = g->builtin_types.entry_invalid;
3894 }3909 }
3895 }3910 }
src/ir.cpp+12-3
...@@ -5300,9 +5300,18 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s...@@ -5300,9 +5300,18 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s
5300 } else {5300 } else {
5301 Tld *tld = find_decl(codegen, parent_scope, name);5301 Tld *tld = find_decl(codegen, parent_scope, name);
5302 if (tld != nullptr) {5302 if (tld != nullptr) {
5303 ErrorMsg *msg = add_node_error(codegen, node,5303 bool want_err_msg = true;
5304 buf_sprintf("redefinition of '%s'", buf_ptr(name)));5304 if (tld->id == TldIdVar) {
5305 add_error_note(codegen, msg, tld->source_node, buf_sprintf("previous definition is here"));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 }
5306 variable_entry->var_type = codegen->builtin_types.entry_invalid;5315 variable_entry->var_type = codegen->builtin_types.entry_invalid;
5307 }5316 }
5308 }5317 }