| author | |
| committer | |
| log | 34eff503265834172f89a8635e49e9f4d124db51 |
| tree | d18cc0735ffcbe09dabb9ec3a7f32a7bbc20b1a9 |
| parent | 0e77b0ac8936b0f09deb23733fe5a772869a64e6 |
closes #3152 files changed, 16 insertions(+), 2 deletions(-)
src/ir.cpp+1-2| ... | ... | @@ -8212,10 +8212,9 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 8212 | 8212 | bool comptime_var_mem = ir_get_var_is_comptime(var); |
| 8213 | 8213 | |
| 8214 | 8214 | ConstExprValue *mem_slot = nullptr; |
| 8215 | FnTableEntry *fn_entry = scope_fn_entry(var->parent_scope); | |
| 8216 | 8215 | if (var->value->special == ConstValSpecialStatic) { |
| 8217 | 8216 | mem_slot = var->value; |
| 8218 | } else if (fn_entry) { | |
| 8217 | } else { | |
| 8219 | 8218 | // TODO once the analyze code is fully ported over to IR we won't need this SIZE_MAX thing. |
| 8220 | 8219 | if (var->mem_slot_index != SIZE_MAX && (comptime_var_mem || var->gen_is_const)) |
| 8221 | 8220 | mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index]; |
test/cases/eval.zig+15| ... | ... | @@ -299,3 +299,18 @@ const Foo = struct { |
| 299 | 299 | |
| 300 | 300 | var foo_contents = Foo { .name = "a", }; |
| 301 | 301 | const foo_ref = &foo_contents; |
| 302 | ||
| 303 | ||
| 304 | ||
| 305 | test "create global array with for loop" { | |
| 306 | assert(global_array[5] == 5 * 5); | |
| 307 | assert(global_array[9] == 9 * 9); | |
| 308 | } | |
| 309 | ||
| 310 | const global_array = { | |
| 311 | var result: [10]usize = undefined; | |
| 312 | for (result) |*item, index| { | |
| 313 | *item = index * index; | |
| 314 | } | |
| 315 | result | |
| 316 | }; |