diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-02-25 12:54:40 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-02-26 12:51:23 -0700 |
| commit | ee149aaa03e586e48c32cce09bf488ae0e88d053 (patch) | |
| tree | 786f7b54e7e47027ee66e3fd2c412bed4a31b7bf /test/behavior/struct.zig | |
| parent | b3aa1ab693ac160a07c44f07c7b90577039860a1 (diff) | |
| download | zig-ee149aaa03e586e48c32cce09bf488ae0e88d053.tar.gz zig-ee149aaa03e586e48c32cce09bf488ae0e88d053.zip | |
stage2: actually coerce in coerce_result_ptr at comptime
Diffstat (limited to 'test/behavior/struct.zig')
| -rw-r--r-- | test/behavior/struct.zig | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index a1d60632a9..1da2b0373d 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -1237,3 +1237,28 @@ test "anon init through error union" { try S.doTheTest(); comptime try S.doTheTest(); } + +test "typed init through error unions and optionals" { + if (builtin.zig_backend == .stage1) return error.SkipZigTest; + if (builtin.zig_backend != .stage2_llvm) return error.SkipZigTest; // TODO + + const S = struct { + a: u32, + + fn foo() anyerror!?anyerror!@This() { + return @This(){ .a = 1 }; + } + fn bar() ?anyerror![2]u8 { + return [2]u8{ 1, 2 }; + } + + fn doTheTest() !void { + var a = try (try foo()).?; + var b = try bar().?; + try expect(a.a + b[1] == 3); + } + }; + + try S.doTheTest(); + comptime try S.doTheTest(); +} |
