| ... | @@ -3183,15 +3183,26 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue { | ... | @@ -3183,15 +3183,26 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue { |
| 3183 | const kv = try mod.getErrorValue(name); | 3183 | const kv = try mod.getErrorValue(name); |
| 3184 | return WValue{ .imm32 = kv.value }; | 3184 | return WValue{ .imm32 = kv.value }; |
| 3185 | }, | 3185 | }, |
| 3186 | .error_union => { | 3186 | .error_union => |error_union| { |
| 3187 | const error_type = ty.errorUnionSet(mod); | 3187 | const err_tv: TypedValue = switch (error_union.val) { |
| | 3188 | .err_name => |err_name| .{ |
| | 3189 | .ty = ty.errorUnionSet(mod), |
| | 3190 | .val = (try mod.intern(.{ .err = .{ |
| | 3191 | .ty = ty.errorUnionSet(mod).toIntern(), |
| | 3192 | .name = err_name, |
| | 3193 | } })).toValue(), |
| | 3194 | }, |
| | 3195 | .payload => .{ |
| | 3196 | .ty = Type.err_int, |
| | 3197 | .val = try mod.intValue(Type.err_int, 0), |
| | 3198 | }, |
| | 3199 | }; |
| 3188 | const payload_type = ty.errorUnionPayload(mod); | 3200 | const payload_type = ty.errorUnionPayload(mod); |
| 3189 | if (!payload_type.hasRuntimeBitsIgnoreComptime(mod)) { | 3201 | if (!payload_type.hasRuntimeBitsIgnoreComptime(mod)) { |
| 3190 | // We use the error type directly as the type. | 3202 | // We use the error type directly as the type. |
| 3191 | const is_pl = val.errorUnionIsPayload(mod); | 3203 | return func.lowerConstant(err_tv.val, err_tv.ty); |
| 3192 | const err_val = if (!is_pl) val else try mod.intValue(error_type, 0); | | |
| 3193 | return func.lowerConstant(err_val, error_type); | | |
| 3194 | } | 3204 | } |
| | 3205 | |
| 3195 | return func.fail("Wasm TODO: lowerConstant error union with non-zero-bit payload type", .{}); | 3206 | return func.fail("Wasm TODO: lowerConstant error union with non-zero-bit payload type", .{}); |
| 3196 | }, | 3207 | }, |
| 3197 | .enum_tag => |enum_tag| { | 3208 | .enum_tag => |enum_tag| { |