Sema: correct condition in validateArrayInit

Closes #13425
This commit is contained in:
Veikka Tuominen 2022-11-04 17:47:53 +02:00
parent 799a558e39
commit 35afa3fd8b
2 changed files with 23 additions and 1 deletions

View File

@ -4380,7 +4380,7 @@ fn zirValidateArrayInit(
var block_index = block.instructions.items.len - 1;
while (block.instructions.items[block_index] != elem_ptr_air_inst) {
if (block_index == 0) {
array_is_comptime = true;
array_is_comptime = false;
continue :outer;
}
block_index -= 1;

View File

@ -574,3 +574,25 @@ test "tuple to array handles sentinel" {
};
try expect(S.b[0] == 1);
}
test "array init of container level array variable" {
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
const S = struct {
var pair: [2]usize = .{ 1, 2 };
noinline fn foo(x: usize, y: usize) void {
pair = [2]usize{ x, y };
}
noinline fn bar(x: usize, y: usize) void {
var tmp: [2]usize = .{ x, y };
pair = tmp;
}
};
try expectEqual([2]usize{ 1, 2 }, S.pair);
S.foo(3, 4);
try expectEqual([2]usize{ 3, 4 }, S.pair);
S.bar(5, 6);
try expectEqual([2]usize{ 5, 6 }, S.pair);
}