| ... | ... | @@ -2289,13 +2289,21 @@ VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent |
| 2289 | 2289 | add_node_error(g, source_node, |
| 2290 | 2290 | buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name))); |
| 2291 | 2291 | variable_entry->value->type = g->builtin_types.entry_invalid; |
| 2292 | | } else if (src_tld == nullptr) { |
| 2293 | | Tld *tld = find_decl(g, parent_scope, name); |
| 2294 | | if (tld) { |
| 2295 | | ErrorMsg *msg = add_node_error(g, source_node, |
| 2296 | | buf_sprintf("redefinition of '%s'", buf_ptr(name))); |
| 2297 | | add_error_note(g, msg, tld->source_node, buf_sprintf("previous definition is here")); |
| 2298 | | variable_entry->value->type = g->builtin_types.entry_invalid; |
| 2292 | } else { |
| 2293 | Scope *search_scope = nullptr; |
| 2294 | if (src_tld == nullptr) { |
| 2295 | search_scope = parent_scope; |
| 2296 | } else if (src_tld->parent_scope != nullptr && src_tld->parent_scope->parent != nullptr) { |
| 2297 | search_scope = src_tld->parent_scope->parent; |
| 2298 | } |
| 2299 | if (search_scope != nullptr) { |
| 2300 | Tld *tld = find_decl(g, search_scope, name); |
| 2301 | if (tld != nullptr) { |
| 2302 | ErrorMsg *msg = add_node_error(g, source_node, |
| 2303 | buf_sprintf("redefinition of '%s'", buf_ptr(name))); |
| 2304 | add_error_note(g, msg, tld->source_node, buf_sprintf("previous definition is here")); |
| 2305 | variable_entry->value->type = g->builtin_types.entry_invalid; |
| 2306 | } |
| 2299 | 2307 | } |
| 2300 | 2308 | } |
| 2301 | 2309 | } |