$ fix eval --expr "$(python3 -c 'print("with { a = 1; }; "*255 + "a")')"
1
$ fix eval --expr "$(python3 -c 'print("with { a = 1; }; "*256 + "a")')"
thread 16530570 panic: integer overflow
scope_depth is a u8 (src/expr/compiler/context.zig:117), and beginScope increments it unguarded.
The panic is the good case. In ReleaseFast the increment wraps to 0, and endScope (src/expr/compiler/scope.zig:20) then pops against a bogus depth:
pub fn endScope(self: *Compiler) void {
self.scope_depth -= 1;
while (self.locals.items.len > 0) {
const local = self.locals.items[self.locals.items.len - 1];
if (local.depth <= self.scope_depth) break;
_ = self.locals.pop();
}
}
With a wrapped scope_depth the wrong locals are popped and the result is a silent scoping bug rather than a crash.
declareLocal already handles its own limit properly with error.TooManyLocals; the same treatment here would be consistent.
fix 0.3.0 at 1f1a99cf, built -Doptimize=ReleaseSafe with Zig 0.16.0, darwin/aarch64. Reference implementation is Nix 2.34.8.
scope_depthis au8(src/expr/compiler/context.zig:117), andbeginScopeincrements it unguarded.The panic is the good case. In ReleaseFast the increment wraps to 0, and
endScope(src/expr/compiler/scope.zig:20) then pops against a bogus depth:With a wrapped
scope_depththe wrong locals are popped and the result is a silent scoping bug rather than a crash.declareLocalalready handles its own limit properly witherror.TooManyLocals; the same treatment here would be consistent.fix 0.3.0 at
1f1a99cf, built-Doptimize=ReleaseSafewith Zig 0.16.0, darwin/aarch64. Reference implementation is Nix 2.34.8.