| author | |
| committer | |
| log | 8f5db19791dde73e8e969c6ebf821767f1c3e50b |
| tree | dc1337c0ff763087963f524e4f8d6e0c18fb887a |
| parent | e52232cd570935d7880cbfe52215dbdf0f2d2243 |
| signature |
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: #300392 files changed, 12 insertions(+), 1 deletions(-)
src/Sema.zig+3-1| ... | ... | @@ -175,9 +175,11 @@ const ComptimeAlloc = struct { |
| 175 | 175 | |
| 176 | 176 | /// `src` may be `null` if `is_const` will be set. |
| 177 | 177 | fn 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); | |
| 178 | 180 | const idx = sema.comptime_allocs.items.len; |
| 179 | 181 | try sema.comptime_allocs.append(sema.gpa, .{ |
| 180 | .val = .{ .interned = try sema.pt.intern(.{ .undef = ty.toIntern() }) }, | |
| 182 | .val = .{ .interned = init_val.toIntern() }, | |
| 181 | 183 | .is_const = false, |
| 182 | 184 | .src = src, |
| 183 | 185 | .alignment = alignment, |
test/behavior/type.zig+9| ... | ... | @@ -427,3 +427,12 @@ test "undefined type value" { |
| 427 | 427 | }; |
| 428 | 428 | comptime assert(@TypeOf(S.undef_type) == type); |
| 429 | 429 | } |
| 430 | ||
| 431 | test "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 | } |