Commit 1acb6a53d0

kcbanner <kcbanner@gmail.com>
2023-10-28 18:38:31
wasm: support rendering unions using their backing type if they have no defined tag type
1 parent 35c8698
Changed files (1)
src
arch
src/arch/wasm/CodeGen.zig
@@ -3372,10 +3372,14 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
         },
         .un => |un| {
             // in this case we have a packed union which will not be passed by reference.
-            const union_obj = mod.typeToUnion(ty).?;
-            const field_index = mod.unionTagFieldIndex(union_obj, un.tag.toValue()).?;
-            const field_ty = union_obj.field_types.get(ip)[field_index].toType();
-            return func.lowerConstant(un.val.toValue(), field_ty);
+            const constant_ty = if (un.tag == .none)
+                try ty.unionBackingType(mod)
+            else field_ty: {
+                const union_obj = mod.typeToUnion(ty).?;
+                const field_index = mod.unionTagFieldIndex(union_obj, un.tag.toValue()).?;
+                break :field_ty union_obj.field_types.get(ip)[field_index].toType();
+            };
+            return func.lowerConstant(un.val.toValue(), constant_ty);
         },
         .memoized_call => unreachable,
     }