diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-05-07 13:21:53 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-05-07 13:21:53 -0400 |
| commit | 11d8a8cc7b6984f2c79923a5e3f763003f2b558f (patch) | |
| tree | 20151d02f9d0157abefa0e006dff282af5f64a1d /test | |
| parent | 818a0a26291cf456cfaa955401b1aa8219737d6c (diff) | |
| download | zig-11d8a8cc7b6984f2c79923a5e3f763003f2b558f.tar.gz zig-11d8a8cc7b6984f2c79923a5e3f763003f2b558f.zip | |
fix comptime switch on enum with ref payload
See #43
Diffstat (limited to 'test')
| -rw-r--r-- | test/cases/switch.zig | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/cases/switch.zig b/test/cases/switch.zig index ccacbd1c78..dfec42ea87 100644 --- a/test/cases/switch.zig +++ b/test/cases/switch.zig @@ -106,6 +106,22 @@ fn switchProngWithVarFn(a: &const SwitchProngWithVarEnum) { } } +test "switch on enum using pointer capture" { + testSwitchEnumPtrCapture(); + comptime testSwitchEnumPtrCapture(); +} + +fn testSwitchEnumPtrCapture() { + var value = SwitchProngWithVarEnum.One { 1234 }; + switch (value) { + SwitchProngWithVarEnum.One => |*x| *x += 1, + else => unreachable, + } + switch (value) { + SwitchProngWithVarEnum.One => |x| assert(x == 1235), + else => unreachable, + } +} test "switch with multiple expressions" { const x = switch (returnsFive()) { @@ -188,3 +204,4 @@ fn testSwitchHandleAllCasesRange(x: u8) -> u8 { 204 ... 255 => 3, } } + |
