mirror of
https://github.com/ziglang/zig.git
synced 2026-02-20 00:08:56 +00:00
wasm: support rendering unions using their backing type if they have no defined tag type
This commit is contained in:
parent
35c86984a6
commit
1acb6a53d0
@ -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,
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user