From e52232cd570935d7880cbfe52215dbdf0f2d2243 Mon Sep 17 00:00:00 2001 From: Matthew Lugg Date: Sat, 29 Nov 2025 11:55:26 +0000 Subject: [PATCH 1/2] print_zir: fix typo --- src/print_zir.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/print_zir.zig b/src/print_zir.zig index 316632f2d3..78b451a3f1 100644 --- a/src/print_zir.zig +++ b/src/print_zir.zig @@ -595,7 +595,7 @@ const Writer = struct { }, .reify_slice_arg_ty => { - const reify_slice_arg_info: Zir.Inst.ReifySliceArgInfo = @enumFromInt(extended.operand); + const reify_slice_arg_info: Zir.Inst.ReifySliceArgInfo = @enumFromInt(extended.small); const extra = self.code.extraData(Zir.Inst.UnNode, extended.operand).data; try stream.print("{t}, ", .{reify_slice_arg_info}); try self.writeInstRef(stream, extra.operand); From 8f5db19791dde73e8e969c6ebf821767f1c3e50b Mon Sep 17 00:00:00 2001 From: Matthew Lugg Date: Sat, 29 Nov 2025 11:55:36 +0000 Subject: [PATCH 2/2] Sema: initialize OPV comptime allocs correctly This was caused a `[0]std.builtin.Type.StructField.Attributes` to be considered `undefined`, even though that type is OPV so should prefer its OPV `.{}` over `undefined`. Resolves: #30039 --- src/Sema.zig | 4 +++- test/behavior/type.zig | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Sema.zig b/src/Sema.zig index 324f1b6867..d31447544c 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -175,9 +175,11 @@ const ComptimeAlloc = struct { /// `src` may be `null` if `is_const` will be set. fn newComptimeAlloc(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type, alignment: Alignment) !ComptimeAllocIndex { + const pt = sema.pt; + const init_val = try sema.typeHasOnePossibleValue(ty) orelse try pt.undefValue(ty); const idx = sema.comptime_allocs.items.len; try sema.comptime_allocs.append(sema.gpa, .{ - .val = .{ .interned = try sema.pt.intern(.{ .undef = ty.toIntern() }) }, + .val = .{ .interned = init_val.toIntern() }, .is_const = false, .src = src, .alignment = alignment, diff --git a/test/behavior/type.zig b/test/behavior/type.zig index 411a77f9e5..ef27522a63 100644 --- a/test/behavior/type.zig +++ b/test/behavior/type.zig @@ -427,3 +427,12 @@ test "undefined type value" { }; comptime assert(@TypeOf(S.undef_type) == type); } + +test "reify struct with zero fields through const arrays" { + const names: [0][]const u8 = .{}; + const types: [0]type = .{}; + const attrs: [0]std.builtin.Type.StructField.Attributes = .{}; + const S = @Struct(.auto, null, &names, &types, &attrs); + comptime assert(@typeInfo(S) == .@"struct"); + comptime assert(@typeInfo(S).@"struct".fields.len == 0); +}