add error for shadowing a type

closes #61
This commit is contained in:
Andrew Kelley
2016-01-18 17:04:37 -07:00
parent 32821e7098
commit ea21d2beb6
2 changed files with 22 additions and 0 deletions

View File

@@ -2072,6 +2072,18 @@ static VariableTableEntry *add_local_var(CodeGen *g, AstNode *source_node, Block
if (existing_var) {
add_node_error(g, source_node, buf_sprintf("redeclaration of variable '%s'", buf_ptr(name)));
variable_entry->type = g->builtin_types.entry_invalid;
} else {
auto primitive_table_entry = g->primitive_type_table.maybe_get(name);
TypeTableEntry *type;
if (primitive_table_entry) {
type = primitive_table_entry->value;
} else {
type = find_container(context, name);
}
if (type) {
add_node_error(g, source_node, buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));
variable_entry->type = g->builtin_types.entry_invalid;
}
}
context->variable_table.put(&variable_entry->name, variable_entry);