diff options
| author | kcbanner <kcbanner@gmail.com> | 2023-09-20 23:53:06 -0400 |
|---|---|---|
| committer | kcbanner <kcbanner@gmail.com> | 2023-09-23 13:04:56 -0400 |
| commit | 2fddd767ba20374e7677003c101e60f470c3804c (patch) | |
| tree | 91ffbed5086771488201cebd82be6e1554ac14b5 /src/codegen.zig | |
| parent | ce919ccf45951856a762ffdb8ef850301cd8c588 (diff) | |
| download | zig-2fddd767ba20374e7677003c101e60f470c3804c.tar.gz zig-2fddd767ba20374e7677003c101e60f470c3804c.zip | |
sema: add support for unions in readFromMemory and writeToMemory
Diffstat (limited to 'src/codegen.zig')
| -rw-r--r-- | src/codegen.zig | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/codegen.zig b/src/codegen.zig index 992b51c635..f34c97e6e5 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -583,7 +583,11 @@ pub fn generateSymbol( } const union_obj = mod.typeToUnion(typed_value.ty).?; - const field_index = typed_value.ty.unionTagFieldIndex(un.tag.toValue(), mod).?; + const field_index = typed_value.ty.unionTagFieldIndex(un.tag.toValue(), mod) 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_index].toType(); if (!field_ty.hasRuntimeBits(mod)) { try code.appendNTimes(0xaa, math.cast(usize, layout.payload_size) orelse return error.Overflow); |
