You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
local variable is never mutated regression for field and array accesses #25540
I've run into this a few times now and thought I was going crazy. Locally, everything would be fine but CI would fail immediately with local variable is never mutated. One reproduction:
> zig1.exe ..\lib build-obj -ofmt=c -Mroot=test.zig
test.zig:2:9: error: local variable is never mutated
var target_path_w: []const u8 = "foo";
^~~~~~~~~~~~~
test.zig:2:9: note: consider using 'const'
With a stage3 compiler, it does not:
> zig build-obj -ofmt=c -Mroot=test.zig
Note that it's not related to the function being unused or something like that. If you add a test block:
test"foo" {
foo();
}
it passes:
> zig test test.zig
All 1 tests passed.
Somewhat surprisingly, zig1 seems to have the more correct behavior, as in each case I've hit, the error seems applicable.
Expected Behavior
zig1 and the stage3 compiler to agree on when things are never mutated.
changed the title [-]`local variable is never mutated` mismatch between zig1 and zig (stage3)[/-][+]`local variable is never mutated` regression, mismatch between zig1 and zig (stage3)[/+]on Oct 11, 2025
changed the title [-]`local variable is never mutated` regression, mismatch between zig1 and zig (stage3)[/-][+]`local variable is never mutated` regression for field and array accesses[/+]on Oct 11, 2025
Activity
squeek502 commentedon Oct 11, 2025
This is actually #25154 (review), so it regressed in #25154 and zig1.wasm hasn't been updated since.
If there was a follow-up issue made, then this should be closed as a duplicate of that. If not, then I guess this can serve as that follow-up issue.
cc @mlugg
[-]`local variable is never mutated` mismatch between zig1 and zig (stage3)[/-][+]`local variable is never mutated` regression, mismatch between zig1 and zig (stage3)[/+]mlugg commentedon Oct 11, 2025
Ah yes, thank you @squeek502; indeed I forgot to make that issue, so this can serve as it.
[-]`local variable is never mutated` regression, mismatch between zig1 and zig (stage3)[/-][+]`local variable is never mutated` regression for field and array accesses[/+]mlugg commentedon Jan 30, 2026
Migrated to https://codeberg.org/ziglang/zig/issues/31049