From 3a30f0fa505e25c98772f9faffe5490b92773708 Mon Sep 17 00:00:00 2001 From: Ian Johnson Date: Sun, 9 Jul 2023 21:30:56 -0400 Subject: [PATCH] Sema: resolve field type layout for anon struct type info Closes #16148 --- src/Sema.zig | 2 ++ test/behavior/struct.zig | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/Sema.zig b/src/Sema.zig index bfefcef8e2..9f2c577a0b 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -17293,6 +17293,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai } }); }; + try sema.resolveTypeLayout(field_ty.toType()); + const is_comptime = field_val != .none; const opt_default_val = if (is_comptime) field_val.toValue() else null; const default_val_ptr = try sema.optRefValue(block, field_ty.toType(), opt_default_val); diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index ab7b97ae94..72553e4058 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -1712,3 +1712,14 @@ test "extern struct field pointer has correct alignment" { try S.doTheTest(); try comptime S.doTheTest(); } + +test "packed struct field in anonymous struct" { + const T = packed struct { + f1: bool = false, + }; + + try std.testing.expect(countFields(.{ .t = T{} }) == 1); +} +fn countFields(v: anytype) usize { + return @typeInfo(@TypeOf(v)).Struct.fields.len; +}