aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/if.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-10-02 20:15:03 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-10-02 20:15:03 -0700
commitc4df9bf56f204f63f4e87255933ba453d69d0182 (patch)
tree647cec61769d5723385f8ac9b1392b3c935a219b /test/behavior/if.zig
parent61a53a587558ff1fe1b0ec98bb424022885edccf (diff)
downloadzig-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.zig15
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();
+}