aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
authorJohn Schmidt <john.schmidt.h@gmail.com>2022-02-12 16:57:52 +0100
committerJohn Schmidt <john.schmidt.h@gmail.com>2022-03-25 23:15:37 +0100
commita7b3082ba0d07c66d2ec19304ffe993d77f714b7 (patch)
tree9631a700dd082721a43bc52055fdb4201ef10641 /src/type.zig
parent1c33ea2c35e9260babedb116ad527256e0a4ef5e (diff)
downloadzig-a7b3082ba0d07c66d2ec19304ffe993d77f714b7.tar.gz
zig-a7b3082ba0d07c66d2ec19304ffe993d77f714b7.zip
Implement `type.bitSize` for unions
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/type.zig b/src/type.zig
index d5b8e6f5b3..6b7214888d 100644
--- 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 => {