From 2fddd767ba20374e7677003c101e60f470c3804c Mon Sep 17 00:00:00 2001 From: kcbanner Date: Wed, 20 Sep 2023 23:53:06 -0400 Subject: sema: add support for unions in readFromMemory and writeToMemory --- src/codegen/c.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/codegen/c.zig') diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 54e13db9a1..0b634e5038 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -1439,7 +1439,10 @@ pub const DeclGen = struct { } const union_obj = mod.typeToUnion(ty).?; - const field_i = mod.unionTagFieldIndex(union_obj, un.tag.toValue()).?; + const field_i = mod.unionTagFieldIndex(union_obj, un.tag.toValue()) orelse f: { + assert(union_obj.getLayout(ip) == .Extern); + break :f mod.unionLargestField(union_obj).index; + }; const field_ty = union_obj.field_types.get(ip)[field_i].toType(); const field_name = union_obj.field_names.get(ip)[field_i]; if (union_obj.getLayout(ip) == .Packed) { -- cgit v1.2.3