Skip to content

Commit da195f9

Browse files
committed
wasm: support rendering unions using their backing type if they have no defined tag type
1 parent 1b37dc8 commit da195f9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/arch/wasm/CodeGen.zig

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3372,10 +3372,14 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
33723372
},
33733373
.un => |un| {
33743374
// in this case we have a packed union which will not be passed by reference.
3375-
const union_obj = mod.typeToUnion(ty).?;
3376-
const field_index = mod.unionTagFieldIndex(union_obj, un.tag.toValue()).?;
3377-
const field_ty = union_obj.field_types.get(ip)[field_index].toType();
3378-
return func.lowerConstant(un.val.toValue(), field_ty);
3375+
const constant_ty = if (un.tag == .none)
3376+
try ty.unionBackingType(mod)
3377+
else field_ty: {
3378+
const union_obj = mod.typeToUnion(ty).?;
3379+
const field_index = mod.unionTagFieldIndex(union_obj, un.tag.toValue()).?;
3380+
break :field_ty union_obj.field_types.get(ip)[field_index].toType();
3381+
};
3382+
return func.lowerConstant(un.val.toValue(), constant_ty);
33793383
},
33803384
.memoized_call => unreachable,
33813385
}

0 commit comments

Comments
 (0)