| ... | @@ -656,3 +656,25 @@ test "switch capture copies its payload" { | ... | @@ -656,3 +656,25 @@ test "switch capture copies its payload" { |
| 656 | try S.doTheTest(); | 656 | try S.doTheTest(); |
| 657 | comptime try S.doTheTest(); | 657 | comptime try S.doTheTest(); |
| 658 | } | 658 | } |
| | 659 | |
| | 660 | test "capture of integer forwards the switch condition directly" { |
| | 661 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| | 662 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| | 663 | |
| | 664 | const S = struct { |
| | 665 | fn foo(x: u8) !void { |
| | 666 | switch (x) { |
| | 667 | 40...45 => |capture| { |
| | 668 | try expect(capture == 42); |
| | 669 | }, |
| | 670 | else => |capture| { |
| | 671 | try expect(capture == 100); |
| | 672 | }, |
| | 673 | } |
| | 674 | } |
| | 675 | }; |
| | 676 | try S.foo(42); |
| | 677 | try S.foo(100); |
| | 678 | comptime try S.foo(42); |
| | 679 | comptime try S.foo(100); |
| | 680 | } |