authorgravatar for pentuppup@noreply.codeberg.orgpentuppup <pentuppup@noreply.codeberg.org> 2026-08-17 13:04:17-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-08-20 21:49:32+02:00
log6e66f7f2b80b0c12b1a2fc1203bc780dbf89294c
treed08643e326ce5373c977d8276519a052fb5ba26d
parent7eeb21f3a65ceabd2fce766c9a56bee68b92b380

AstGen: fix alloc in comptime destructure


2 files changed, 6 insertions(+), 4 deletions(-)

lib/std/zig/AstGen.zig+3-3
......@@ -3489,10 +3489,10 @@ fn assignDestructureMaybeDecls(
34893489 // Typed alloc
34903490 const type_inst = try typeExpr(gz, scope, type_node);
34913491 const ptr = if (align_inst == .none) ptr: {
3492 const tag: Zir.Inst.Tag = if (is_const)
3493 .alloc
3494 else if (this_variable_comptime)
3492 const tag: Zir.Inst.Tag = if (this_variable_comptime)
34953493 .alloc_comptime_mut
3494 else if (is_const)
3495 .alloc
34963496 else
34973497 .alloc_mut;
34983498 break :ptr try gz.addUnNode(tag, type_inst, node);
test/behavior/destructure.zig+3-1
......@@ -27,14 +27,16 @@ test "destructure with comptime syntax" {
2727 fn doTheTest() !void {
2828 {
2929 comptime var x: f32 = undefined;
30 comptime x, const y, var z = .{ 0.5, 123, 456 }; // z is a comptime var
30 comptime x, const y, var z, const w: u32 = .{ 0.5, 123, 456, 789 }; // z is a comptime var
3131 _ = &z;
3232
3333 comptime assert(@TypeOf(y) == comptime_int);
3434 comptime assert(@TypeOf(z) == comptime_int);
35 comptime assert(@TypeOf(w) == u32);
3536 comptime assert(x == 0.5);
3637 comptime assert(y == 123);
3738 comptime assert(z == 456);
39 comptime assert(w == 789);
3840 }
3941 {
4042 var w: u8, var x: u8 = .{ 1, 2 };