authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-04 17:47:53+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-04 23:13:49+02:00
log35afa3fd8bdc140baf9d135711833e836de04d86
tree37ad1c960d929b520da6ef336c5ea0a237292f38
parent799a558e393d1c8286e8faec2bf8930138d8b1f4

Sema: correct condition in validateArrayInit

Closes #13425

2 files changed, 23 insertions(+), 1 deletions(-)

src/Sema.zig+1-1
...@@ -4380,7 +4380,7 @@ fn zirValidateArrayInit(...@@ -4380,7 +4380,7 @@ fn zirValidateArrayInit(
4380 var block_index = block.instructions.items.len - 1;4380 var block_index = block.instructions.items.len - 1;
4381 while (block.instructions.items[block_index] != elem_ptr_air_inst) {4381 while (block.instructions.items[block_index] != elem_ptr_air_inst) {
4382 if (block_index == 0) {4382 if (block_index == 0) {
4383 array_is_comptime = true;4383 array_is_comptime = false;
4384 continue :outer;4384 continue :outer;
4385 }4385 }
4386 block_index -= 1;4386 block_index -= 1;
test/behavior/array.zig+22
...@@ -574,3 +574,25 @@ test "tuple to array handles sentinel" {...@@ -574,3 +574,25 @@ test "tuple to array handles sentinel" {
574 };574 };
575 try expect(S.b[0] == 1);575 try expect(S.b[0] == 1);
576}576}
577
578test "array init of container level array variable" {
579 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
580 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
581 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
582
583 const S = struct {
584 var pair: [2]usize = .{ 1, 2 };
585 noinline fn foo(x: usize, y: usize) void {
586 pair = [2]usize{ x, y };
587 }
588 noinline fn bar(x: usize, y: usize) void {
589 var tmp: [2]usize = .{ x, y };
590 pair = tmp;
591 }
592 };
593 try expectEqual([2]usize{ 1, 2 }, S.pair);
594 S.foo(3, 4);
595 try expectEqual([2]usize{ 3, 4 }, S.pair);
596 S.bar(5, 6);
597 try expectEqual([2]usize{ 5, 6 }, S.pair);
598}