aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-01-18 17:04:37 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-01-18 17:04:37 -0700
commitea21d2beb6cbdac8f5b6811a0f01aa6d2ee2ddf3 (patch)
tree3b277a3570b63f1eeb8fed2218d16bd578f12835 /src/analyze.cpp
parent32821e7098ba29c30e458f555f62954ce54dcb1a (diff)
downloadzig-ea21d2beb6cbdac8f5b6811a0f01aa6d2ee2ddf3.tar.gz
zig-ea21d2beb6cbdac8f5b6811a0f01aa6d2ee2ddf3.zip
add error for shadowing a type
closes #61
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 17a703c439..06f27b323e 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -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);