aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-11-29 18:21:21 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-11-29 18:21:21 -0500
commit815b4cfd9d77e5cf3330cc74caf0987f353a8935 (patch)
tree2e1b7b0f27df4fcc5b495bd1afc9c131005e3393 /test
parentbcdb3a90066148dc5a91d176a8fc7f5d9c7487b1 (diff)
downloadzig-815b4cfd9d77e5cf3330cc74caf0987f353a8935.tar.gz
zig-815b4cfd9d77e5cf3330cc74caf0987f353a8935.zip
fix return result loc as peer result loc in inferred error set function
Diffstat (limited to 'test')
-rw-r--r--test/stage1/behavior/error.zig27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/stage1/behavior/error.zig b/test/stage1/behavior/error.zig
index 9b7904e9cf..f9b331caaf 100644
--- a/test/stage1/behavior/error.zig
+++ b/test/stage1/behavior/error.zig
@@ -400,3 +400,30 @@ test "function pointer with return type that is error union with payload which i
};
S.doTheTest();
}
+
+test "return result loc as peer result loc in inferred error set function" {
+ const S = struct {
+ fn doTheTest() void {
+ if (foo(2)) |x| {
+ expect(x.Two);
+ } else |e| switch (e) {
+ error.Whatever => @panic("fail"),
+ }
+ expectError(error.Whatever, foo(99));
+ }
+ const FormValue = union(enum) {
+ One: void,
+ Two: bool,
+ };
+
+ fn foo(id: u64) !FormValue {
+ return switch (id) {
+ 2 => FormValue{ .Two = true },
+ 1 => FormValue{ .One = {} },
+ else => return error.Whatever,
+ };
+ }
+ };
+ S.doTheTest();
+ comptime S.doTheTest();
+}