zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 34eff503265834172f89a8635e49e9f4d124db51 (tree)
parent 0e77b0ac8936b0f09deb23733fe5a772869a64e6
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Mon, 10 Apr 2017 03:00:19 -0400

fix for loops not working at compile-time

closes #315

Diffstat:
Msrc/ir.cpp | 3+--
Mtest/cases/eval.zig | 15+++++++++++++++
2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/ir.cpp b/src/ir.cpp @@ -8212,10 +8212,9 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, bool comptime_var_mem = ir_get_var_is_comptime(var); ConstExprValue *mem_slot = nullptr; - FnTableEntry *fn_entry = scope_fn_entry(var->parent_scope); if (var->value->special == ConstValSpecialStatic) { mem_slot = var->value; - } else if (fn_entry) { + } else { // TODO once the analyze code is fully ported over to IR we won't need this SIZE_MAX thing. if (var->mem_slot_index != SIZE_MAX && (comptime_var_mem || var->gen_is_const)) mem_slot = &ira->exec_context.mem_slot_list[var->mem_slot_index]; diff --git a/test/cases/eval.zig b/test/cases/eval.zig @@ -299,3 +299,18 @@ const Foo = struct { var foo_contents = Foo { .name = "a", }; const foo_ref = &foo_contents; + + + +test "create global array with for loop" { + assert(global_array[5] == 5 * 5); + assert(global_array[9] == 9 * 9); +} + +const global_array = { + var result: [10]usize = undefined; + for (result) |*item, index| { + *item = index * index; + } + result +};