diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-10-02 20:15:03 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-10-02 20:15:03 -0700 |
| commit | c4df9bf56f204f63f4e87255933ba453d69d0182 (patch) | |
| tree | 647cec61769d5723385f8ac9b1392b3c935a219b /test/behavior/if.zig | |
| parent | 61a53a587558ff1fe1b0ec98bb424022885edccf (diff) | |
| download | zig-c4df9bf56f204f63f4e87255933ba453d69d0182.tar.gz zig-c4df9bf56f204f63f4e87255933ba453d69d0182.zip | |
AstGen: fix `while` and `for` with unreachable bodies
Companion commit to 61a53a587558ff1fe1b0ec98bb424022885edccf.
This commit also moves over a bunch of behavior test cases to the
passing-for-stage2 section.
Diffstat (limited to 'test/behavior/if.zig')
| -rw-r--r-- | test/behavior/if.zig | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/behavior/if.zig b/test/behavior/if.zig index a1f722d827..e907f288de 100644 --- a/test/behavior/if.zig +++ b/test/behavior/if.zig @@ -73,3 +73,18 @@ test "const result loc, runtime if cond, else unreachable" { const x = if (t) Num.Two else unreachable; try expect(x == .Two); } + +test "if copies its payload" { + const S = struct { + fn doTheTest() !void { + var tmp: ?i32 = 10; + if (tmp) |value| { + // Modify the original variable + tmp = null; + try expect(value == 10); + } else unreachable; + } + }; + try S.doTheTest(); + comptime try S.doTheTest(); +} |
