wasm: support rendering unions using their backing type if they have no defined tag type

This commit is contained in:
kcbanner 2023-10-28 12:38:31 -04:00 committed by mlugg
parent 35c86984a6
commit 1acb6a53d0
No known key found for this signature in database
GPG Key ID: E60D96B91E86EF9F

View File

@ -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,
}