aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-04-04 22:46:05 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-04-04 22:46:05 -0700
commit95a87e88fac3fc563ac3baaf4eb8027341f4131e (patch)
tree4b028355d7f38451d7de1cc2977aa59b9543c8f3 /test
parent51ef31a8331e92103253a37ddfdacbd263cee81d (diff)
downloadzig-95a87e88fac3fc563ac3baaf4eb8027341f4131e.tar.gz
zig-95a87e88fac3fc563ac3baaf4eb8027341f4131e.zip
Sema: forward switch condition to captures
Diffstat (limited to 'test')
-rw-r--r--test/behavior/switch.zig22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/behavior/switch.zig b/test/behavior/switch.zig
index b988f32a38..2d10ad0a13 100644
--- a/test/behavior/switch.zig
+++ b/test/behavior/switch.zig
@@ -656,3 +656,25 @@ test "switch capture copies its payload" {
try S.doTheTest();
comptime try S.doTheTest();
}
+
+test "capture of integer forwards the switch condition directly" {
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ fn foo(x: u8) !void {
+ switch (x) {
+ 40...45 => |capture| {
+ try expect(capture == 42);
+ },
+ else => |capture| {
+ try expect(capture == 100);
+ },
+ }
+ }
+ };
+ try S.foo(42);
+ try S.foo(100);
+ comptime try S.foo(42);
+ comptime try S.foo(100);
+}