aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/if.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-10-28 17:23:02 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-10-28 17:23:02 -0700
commit1c93cf52d8b8acab469efe5d4457ed43d76bc6e5 (patch)
tree7f85f232fe39aeb3ab43d13dd29ecd70f9921d55 /test/behavior/if.zig
parentc59ee3157f5a7fb5c6110422ea8215601285ea28 (diff)
downloadzig-1c93cf52d8b8acab469efe5d4457ed43d76bc6e5.tar.gz
zig-1c93cf52d8b8acab469efe5d4457ed43d76bc6e5.zip
C backend: fix crash when number of Decls passes a threshold
The ensureUnusedCapacity did not reserve a big enough number. I changed it to no longer guess the capacity because I saw that the number of possible items was not determinable ahead of time and this can therefore avoid allocating more memory than necessary.
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();
+}