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(...@@ -3489,10 +3489,10 @@ fn assignDestructureMaybeDecls(
3489 // Typed alloc3489 // Typed alloc
3490 const type_inst = try typeExpr(gz, scope, type_node);3490 const type_inst = try typeExpr(gz, scope, type_node);
3491 const ptr = if (align_inst == .none) ptr: {3491 const ptr = if (align_inst == .none) ptr: {
3492 const tag: Zir.Inst.Tag = if (is_const)3492 const tag: Zir.Inst.Tag = if (this_variable_comptime)
3493 .alloc
3494 else if (this_variable_comptime)
3495 .alloc_comptime_mut3493 .alloc_comptime_mut
3494 else if (is_const)
3495 .alloc
3496 else3496 else
3497 .alloc_mut;3497 .alloc_mut;
3498 break :ptr try gz.addUnNode(tag, type_inst, node);3498 break :ptr try gz.addUnNode(tag, type_inst, node);
test/behavior/destructure.zig+3-1
...@@ -27,14 +27,16 @@ test "destructure with comptime syntax" {...@@ -27,14 +27,16 @@ test "destructure with comptime syntax" {
27 fn doTheTest() !void {27 fn doTheTest() !void {
28 {28 {
29 comptime var x: f32 = undefined;29 comptime var x: f32 = undefined;
30 comptime x, const y, var z = .{ 0.5, 123, 456 }; // z is a comptime var30 comptime x, const y, var z, const w: u32 = .{ 0.5, 123, 456, 789 }; // z is a comptime var
31 _ = &z;31 _ = &z;
3232
33 comptime assert(@TypeOf(y) == comptime_int);33 comptime assert(@TypeOf(y) == comptime_int);
34 comptime assert(@TypeOf(z) == comptime_int);34 comptime assert(@TypeOf(z) == comptime_int);
35 comptime assert(@TypeOf(w) == u32);
35 comptime assert(x == 0.5);36 comptime assert(x == 0.5);
36 comptime assert(y == 123);37 comptime assert(y == 123);
37 comptime assert(z == 456);38 comptime assert(z == 456);
39 comptime assert(w == 789);
38 }40 }
39 {41 {
40 var w: u8, var x: u8 = .{ 1, 2 };42 var w: u8, var x: u8 = .{ 1, 2 };