| author | |
| committer | |
| log | baa2b62e88c5438c95ab439b12d3bafa55fd21a0 |
| tree | 1e16229de7fe903666cf0f76c294d36c39594cc9 |
| parent | a5e15eced0e9cb00871966ede74eed9b3a07183c |
2 files changed, 18 insertions(+), 2 deletions(-)
src/codegen/c.zig+1-2| ... | ... | @@ -5654,14 +5654,13 @@ fn airErrUnionPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5654 | 5654 | const operand = try f.resolveInst(ty_op.operand); |
| 5655 | 5655 | const error_union_ty = f.typeOf(ty_op.operand).childType(mod); |
| 5656 | 5656 | |
| 5657 | const error_ty = error_union_ty.errorUnionSet(mod); | |
| 5658 | 5657 | const payload_ty = error_union_ty.errorUnionPayload(mod); |
| 5659 | 5658 | |
| 5660 | 5659 | // First, set the non-error value. |
| 5661 | 5660 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) { |
| 5662 | 5661 | try f.writeCValueDeref(writer, operand); |
| 5663 | 5662 | try writer.writeAll(" = "); |
| 5664 | try f.object.dg.renderValue(writer, error_ty, try mod.intValue(error_ty, 0), .Other); | |
| 5663 | try f.object.dg.renderValue(writer, Type.err_int, try mod.intValue(Type.err_int, 0), .Other); | |
| 5665 | 5664 | try writer.writeAll(";\n "); |
| 5666 | 5665 | |
| 5667 | 5666 | return operand; |
test/behavior/error.zig+17| ... | ... | @@ -921,3 +921,20 @@ test "optional error set return type" { |
| 921 | 921 | try expect(null == S.foo(true)); |
| 922 | 922 | try expect(E.A == S.foo(false).?); |
| 923 | 923 | } |
| 924 | ||
| 925 | test "returning an error union containing a type with no runtime bits" { | |
| 926 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | |
| 927 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | |
| 928 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 929 | ||
| 930 | const ZeroByteType = struct { | |
| 931 | foo: void, | |
| 932 | ||
| 933 | pub fn init() !@This() { | |
| 934 | return .{ .foo = {} }; | |
| 935 | } | |
| 936 | }; | |
| 937 | ||
| 938 | var zero_byte: ZeroByteType = undefined; | |
| 939 | (&zero_byte).* = try ZeroByteType.init(); | |
| 940 | } |