diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-10-28 17:23:02 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-10-28 17:23:02 -0700 |
| commit | 1c93cf52d8b8acab469efe5d4457ed43d76bc6e5 (patch) | |
| tree | 7f85f232fe39aeb3ab43d13dd29ecd70f9921d55 /test/behavior/if.zig | |
| parent | c59ee3157f5a7fb5c6110422ea8215601285ea28 (diff) | |
| download | zig-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.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(); +} |
