commit 63dc0447fc4654324ef8efcfa65849f7ef682531 (tree)
parent abded5cbb0b8c0b383b2362a2b89447528fe536c
Author: Andrew Kelley <andrew@ziglang.org>
Date: Fri, 26 May 2023 13:21:35 -0700
wasm: fix error union constant lowering
Diffstat:
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig
@@ -3183,15 +3183,26 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {
const kv = try mod.getErrorValue(name);
return WValue{ .imm32 = kv.value };
},
- .error_union => {
- const error_type = ty.errorUnionSet(mod);
+ .error_union => |error_union| {
+ const err_tv: TypedValue = switch (error_union.val) {
+ .err_name => |err_name| .{
+ .ty = ty.errorUnionSet(mod),
+ .val = (try mod.intern(.{ .err = .{
+ .ty = ty.errorUnionSet(mod).toIntern(),
+ .name = err_name,
+ } })).toValue(),
+ },
+ .payload => .{
+ .ty = Type.err_int,
+ .val = try mod.intValue(Type.err_int, 0),
+ },
+ };
const payload_type = ty.errorUnionPayload(mod);
if (!payload_type.hasRuntimeBitsIgnoreComptime(mod)) {
// We use the error type directly as the type.
- const is_pl = val.errorUnionIsPayload(mod);
- const err_val = if (!is_pl) val else try mod.intValue(error_type, 0);
- return func.lowerConstant(err_val, error_type);
+ return func.lowerConstant(err_tv.val, err_tv.ty);
}
+
return func.fail("Wasm TODO: lowerConstant error union with non-zero-bit payload type", .{});
},
.enum_tag => |enum_tag| {