authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-11-29 20:21:30+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-11-29 20:21:30+01:00
log44e99edd7a12ea7e04fbfe53746c3af4b531f687
treed1e18165c95c127a53655828c6778fc3fa55bf00
parenta0289d0cce370729099a1ec0228e7f49bcdabc80
parent8f5db19791dde73e8e969c6ebf821767f1c3e50b

Merge pull request 'Sema: initialize OPV comptime allocs correctly' (#30043) from reify-empty-struct into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30043

3 files changed, 13 insertions(+), 2 deletions(-)

src/Sema.zig+3-1
......@@ -175,9 +175,11 @@ const ComptimeAlloc = struct {
175175
176176/// `src` may be `null` if `is_const` will be set.
177177fn newComptimeAlloc(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type, alignment: Alignment) !ComptimeAllocIndex {
178 const pt = sema.pt;
179 const init_val = try sema.typeHasOnePossibleValue(ty) orelse try pt.undefValue(ty);
178180 const idx = sema.comptime_allocs.items.len;
179181 try sema.comptime_allocs.append(sema.gpa, .{
180 .val = .{ .interned = try sema.pt.intern(.{ .undef = ty.toIntern() }) },
182 .val = .{ .interned = init_val.toIntern() },
181183 .is_const = false,
182184 .src = src,
183185 .alignment = alignment,
src/print_zir.zig+1-1
......@@ -595,7 +595,7 @@ const Writer = struct {
595595 },
596596
597597 .reify_slice_arg_ty => {
598 const reify_slice_arg_info: Zir.Inst.ReifySliceArgInfo = @enumFromInt(extended.operand);
598 const reify_slice_arg_info: Zir.Inst.ReifySliceArgInfo = @enumFromInt(extended.small);
599599 const extra = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;
600600 try stream.print("{t}, ", .{reify_slice_arg_info});
601601 try self.writeInstRef(stream, extra.operand);
test/behavior/type.zig+9
......@@ -427,3 +427,12 @@ test "undefined type value" {
427427 };
428428 comptime assert(@TypeOf(S.undef_type) == type);
429429}
430
431test "reify struct with zero fields through const arrays" {
432 const names: [0][]const u8 = .{};
433 const types: [0]type = .{};
434 const attrs: [0]std.builtin.Type.StructField.Attributes = .{};
435 const S = @Struct(.auto, null, &names, &types, &attrs);
436 comptime assert(@typeInfo(S) == .@"struct");
437 comptime assert(@typeInfo(S).@"struct".fields.len == 0);
438}