authorgravatar for ian@ianjohnson.devIan Johnson <ian@ianjohnson.dev> 2023-07-09 21:30:56-04:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-07-10 19:17:50+03:00
log3a30f0fa505e25c98772f9faffe5490b92773708
treecf01d2399b43aa5f4b6970422dcbd0683f15367f
parent82a9d5d78d891b093c1755ecd5452b65619fdccf

Sema: resolve field type layout for anon struct type info

Closes #16148

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

src/Sema.zig+2
......@@ -17293,6 +17293,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1729317293 } });
1729417294 };
1729517295
17296 try sema.resolveTypeLayout(field_ty.toType());
17297
1729617298 const is_comptime = field_val != .none;
1729717299 const opt_default_val = if (is_comptime) field_val.toValue() else null;
1729817300 const default_val_ptr = try sema.optRefValue(block, field_ty.toType(), opt_default_val);
test/behavior/struct.zig+11
......@@ -1712,3 +1712,14 @@ test "extern struct field pointer has correct alignment" {
17121712 try S.doTheTest();
17131713 try comptime S.doTheTest();
17141714}
1715
1716test "packed struct field in anonymous struct" {
1717 const T = packed struct {
1718 f1: bool = false,
1719 };
1720
1721 try std.testing.expect(countFields(.{ .t = T{} }) == 1);
1722}
1723fn countFields(v: anytype) usize {
1724 return @typeInfo(@TypeOf(v)).Struct.fields.len;
1725}