diff options
| author | kcbanner <kcbanner@gmail.com> | 2023-10-28 12:38:31 -0400 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2023-11-07 00:49:39 +0000 |
| commit | 1acb6a53d04102ed028b73451df2250bd6d45cd9 (patch) | |
| tree | 3ba059a0ec157c99784385fe26898c1c7d2232ba /src/arch/wasm/CodeGen.zig | |
| parent | 35c86984a6c5e275c5c980ebb9d4b372291c9917 (diff) | |
| download | zig-1acb6a53d04102ed028b73451df2250bd6d45cd9.tar.gz zig-1acb6a53d04102ed028b73451df2250bd6d45cd9.zip | |
wasm: support rendering unions using their backing type if they have no defined tag type
Diffstat (limited to 'src/arch/wasm/CodeGen.zig')
| -rw-r--r-- | src/arch/wasm/CodeGen.zig | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 21ddd91120..7c752490c6 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/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, } |
