aboutsummaryrefslogtreecommitdiff
path: root/test/stage1
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-05-14 18:06:02 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-05-14 18:06:57 -0400
commitdf4f77024e93dc3b60dd1d76d64e3c5ffa5ebd84 (patch)
tree59d5026be2d5840255bf48b8d48a94840c26e0cf /test/stage1
parent6536b409df053165ed704148de6ecf5b72e27282 (diff)
downloadzig-df4f77024e93dc3b60dd1d76d64e3c5ffa5ebd84.tar.gz
zig-df4f77024e93dc3b60dd1d76d64e3c5ffa5ebd84.zip
else value when switching on error set has
optional capture value which is subset. see #769
Diffstat (limited to 'test/stage1')
-rw-r--r--test/stage1/behavior/switch.zig34
1 files changed, 33 insertions, 1 deletions
diff --git a/test/stage1/behavior/switch.zig b/test/stage1/behavior/switch.zig
index 11ed935233..7b6540d852 100644
--- a/test/stage1/behavior/switch.zig
+++ b/test/stage1/behavior/switch.zig
@@ -1,4 +1,6 @@
-const expect = @import("std").testing.expect;
+const std = @import("std");
+const expect = std.testing.expect;
+const expectError = std.testing.expectError;
test "switch with numbers" {
testSwitchWithNumbers(13);
@@ -296,3 +298,33 @@ test "anon enum literal used in switch on union enum" {
},
}
}
+
+test "else prong of switch on error set excludes other cases" {
+ const S = struct {
+ fn doTheTest() void {
+ expectError(error.C, bar());
+ }
+ const E = error{
+ A,
+ B,
+ } || E2;
+
+ const E2 = error{
+ C,
+ D,
+ };
+
+ fn foo() E!void {
+ return error.C;
+ }
+
+ fn bar() E2!void {
+ foo() catch |err| switch (err) {
+ error.A, error.B => {},
+ else => |e| return e,
+ };
+ }
+ };
+ S.doTheTest();
+ comptime S.doTheTest();
+}