commit a7b3082ba0d07c66d2ec19304ffe993d77f714b7 (tree) parent 1c33ea2c35e9260babedb116ad527256e0a4ef5e Author: John Schmidt <john.schmidt.h@gmail.com> Date: Sat, 12 Feb 2022 16:57:52 +0100 Implement `type.bitSize` for unions Diffstat:
| M | src/type.zig | | | 14 | +++++++++++++- |
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/src/type.zig b/src/type.zig @@ -3251,8 +3251,20 @@ pub const Type = extern union { const int_tag_ty = ty.intTagType(&buffer); return int_tag_ty.bitSize(target); }, + .@"union", .union_tagged => { - @panic("TODO bitSize unions"); + const union_obj = ty.cast(Payload.Union).?.data; + + const fields = union_obj.fields; + if (fields.count() == 0) return 0; + + assert(union_obj.haveFieldTypes()); + + var size: u64 = 0; + for (fields.values()) |field| { + size = @maximum(size, field.ty.bitSize(target)); + } + return size; }, .vector => {