diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2023-08-10 03:25:35 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-08-11 11:01:47 -0700 |
| commit | 8b9161179d08a3f1dc22ea61e6165a0c638bfae3 (patch) | |
| tree | 9766bd828e3db022e50808c89c250c3e01b6609b /test/behavior/array.zig | |
| parent | b835fd90cef1447904d3b009c9662ba4c0ea77d4 (diff) | |
| download | zig-8b9161179d08a3f1dc22ea61e6165a0c638bfae3.tar.gz zig-8b9161179d08a3f1dc22ea61e6165a0c638bfae3.zip | |
Sema: avoid deleting runtime side-effects in comptime initializers
Closes #16744
Diffstat (limited to 'test/behavior/array.zig')
| -rw-r--r-- | test/behavior/array.zig | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/behavior/array.zig b/test/behavior/array.zig index a4cac26569..523855161a 100644 --- a/test/behavior/array.zig +++ b/test/behavior/array.zig @@ -775,3 +775,27 @@ test "array init with no result pointer sets field result types" { try expect(y == x); } + +test "runtime side-effects in comptime-known array init" { + var side_effects: u4 = 0; + const init = [4]u4{ + blk: { + side_effects += 1; + break :blk 1; + }, + blk: { + side_effects += 2; + break :blk 2; + }, + blk: { + side_effects += 4; + break :blk 4; + }, + blk: { + side_effects += 8; + break :blk 8; + }, + }; + try expectEqual([4]u4{ 1, 2, 4, 8 }, init); + try expectEqual(@as(u4, std.math.maxInt(u4)), side_effects); +} |
