diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-02-27 00:05:08 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-02-27 00:07:11 -0500 |
| commit | 1195994880b6a83e61807381df2721ac5256e876 (patch) | |
| tree | 7ca30412d5c1ad7a3df15633ac3303b74b49eaf6 /src/analyze.cpp | |
| parent | 25761570f1bb4413020ebbfc959caa3429453517 (diff) | |
| download | zig-1195994880b6a83e61807381df2721ac5256e876.tar.gz zig-1195994880b6a83e61807381df2721ac5256e876.zip | |
fix inability to write to global in some cases
before, when we initialized a variable by copying the
initialization value, it made the internal const value
references point to a duplicate value, resulting in
a phony duplicate global value being updated instead of
the real on. now the behavior is as expected.
thanks to hoppetosse for pointing out this bug on IRC.
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 03da4a26c7..453cefc2f8 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -2085,7 +2085,7 @@ VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent assert(value); VariableTableEntry *variable_entry = allocate<VariableTableEntry>(1); - variable_entry->value = *value; + variable_entry->value = value; variable_entry->parent_scope = parent_scope; variable_entry->shadowable = false; variable_entry->mem_slot_index = SIZE_MAX; @@ -2101,21 +2101,21 @@ VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent ErrorMsg *msg = add_node_error(g, source_node, buf_sprintf("redeclaration of variable '%s'", buf_ptr(name))); add_error_note(g, msg, existing_var->decl_node, buf_sprintf("previous declaration is here")); - variable_entry->value.type = g->builtin_types.entry_invalid; + variable_entry->value->type = g->builtin_types.entry_invalid; } else { auto primitive_table_entry = g->primitive_type_table.maybe_get(name); if (primitive_table_entry) { TypeTableEntry *type = primitive_table_entry->value; add_node_error(g, source_node, buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name))); - variable_entry->value.type = g->builtin_types.entry_invalid; + variable_entry->value->type = g->builtin_types.entry_invalid; } else { Tld *tld = find_decl(g, parent_scope, name); if (tld && tld->id != TldIdVar) { ErrorMsg *msg = add_node_error(g, source_node, buf_sprintf("redefinition of '%s'", buf_ptr(name))); add_error_note(g, msg, tld->source_node, buf_sprintf("previous definition is here")); - variable_entry->value.type = g->builtin_types.entry_invalid; + variable_entry->value->type = g->builtin_types.entry_invalid; } } } @@ -3181,7 +3181,7 @@ uint32_t fn_eval_hash(Scope* scope) { while (scope) { if (scope->id == ScopeIdVarDecl) { ScopeVarDecl *var_scope = (ScopeVarDecl *)scope; - result += hash_const_val(&var_scope->var->value); + result += hash_const_val(var_scope->var->value); } else if (scope->id == ScopeIdFnDef) { ScopeFnDef *fn_scope = (ScopeFnDef *)scope; result += hash_ptr(fn_scope->fn_entry); @@ -3203,9 +3203,9 @@ bool fn_eval_eql(Scope *a, Scope *b) { if (a->id == ScopeIdVarDecl) { ScopeVarDecl *a_var_scope = (ScopeVarDecl *)a; ScopeVarDecl *b_var_scope = (ScopeVarDecl *)b; - if (a_var_scope->var->value.type != b_var_scope->var->value.type) + if (a_var_scope->var->value->type != b_var_scope->var->value->type) return false; - if (!const_values_equal(&a_var_scope->var->value, &b_var_scope->var->value)) + if (!const_values_equal(a_var_scope->var->value, b_var_scope->var->value)) return false; } else if (a->id == ScopeIdFnDef) { ScopeFnDef *a_fn_scope = (ScopeFnDef *)a; |
