diff options
| author | Josh Wolfe <thejoshwolfe@gmail.com> | 2015-12-03 10:19:00 -0700 |
|---|---|---|
| committer | Josh Wolfe <thejoshwolfe@gmail.com> | 2015-12-03 10:19:00 -0700 |
| commit | 708cae3786a5ce103d92bffe7ea8107df039426f (patch) | |
| tree | 57217ddcc48be9759d21e29d6b512d719068b36b /src/analyze.cpp | |
| parent | cb69cb0f26bb496bb0899da7f98767b2de025296 (diff) | |
| download | zig-708cae3786a5ce103d92bffe7ea8107df039426f.tar.gz zig-708cae3786a5ce103d92bffe7ea8107df039426f.zip | |
fix analysis for variable reference
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 1bce9b2383..dc7af6b809 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -345,7 +345,10 @@ static void check_type_compatibility(CodeGen *g, AstNode *node, TypeTableEntry * return; // TODO: is this true? // TODO better error message - add_node_error(g, node, buf_sprintf("type mismatch. expected %s. got %s", buf_ptr(&expected_type->name), buf_ptr(&actual_type->name))); + add_node_error(g, node, + buf_sprintf("type mismatch. expected %s. got %s", + buf_ptr(&expected_type->name), + buf_ptr(&actual_type->name))); } static BlockContext *new_block_context(AstNode *node, BlockContext *parent) { @@ -434,8 +437,8 @@ static TypeTableEntry * analyze_expression(CodeGen *g, ImportTableEntry *import, LocalVariableTableEntry *existing_variable = find_local_variable(context, &variable_declaration->symbol); if (existing_variable) { - add_node_error(g, node, buf_sprintf("redeclaration of variable '%s'.", - buf_ptr(&variable_declaration->symbol))); + add_node_error(g, node, + buf_sprintf("redeclaration of variable '%s'.", buf_ptr(&variable_declaration->symbol))); } else { LocalVariableTableEntry *variable_entry = allocate<LocalVariableTableEntry>(1); buf_init_from_buf(&variable_entry->name, &variable_declaration->symbol); @@ -596,12 +599,11 @@ static TypeTableEntry * analyze_expression(CodeGen *g, ImportTableEntry *import, case NodeTypeSymbol: { Buf *symbol_name = &node->data.symbol; - FnTableEntry *fn_table_entry = get_context_fn_entry(context); - auto table_entry = fn_table_entry->symbol_table.maybe_get(symbol_name); - if (table_entry) { - SymbolTableEntry *symbol_entry = table_entry->value; - return_type = symbol_entry->type_entry; + LocalVariableTableEntry *local_variable = find_local_variable(context, symbol_name); + if (local_variable) { + return_type = local_variable->type; } else { + // TODO: check global variables also add_node_error(g, node, buf_sprintf("use of undeclared identifier '%s'", buf_ptr(symbol_name))); return_type = g->builtin_types.entry_invalid; @@ -718,8 +720,8 @@ static void analyze_top_level_declaration(CodeGen *g, ImportTableEntry *import, // unique definition context->variable_table.put(&variable_entry->name, variable_entry); } else { - add_node_error(g, node, buf_sprintf("redeclaration of parameter '%s'.", - buf_ptr(&existing_entry->name))); + add_node_error(g, node, + buf_sprintf("redeclaration of parameter '%s'.", buf_ptr(&existing_entry->name))); if (existing_entry->type == variable_entry->type) { // types agree, so the type is probably good enough for the rest of analysis } else { |
