Zig Version
0.16.0-dev.699+529aa9f27
Steps to Reproduce and Observed Behavior
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:
fn foo() void {
var target_path_w: []const u8 = "foo";
_ = target_path_w.len;
}
With zig1, it hits this error:
> 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:
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.
Zig Version
0.16.0-dev.699+529aa9f27
Steps to Reproduce and Observed Behavior
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:With
zig1, it hits this error:With a stage3 compiler, it does not:
Note that it's not related to the function being unused or something like that. If you add a test block:
it passes:
Somewhat surprisingly,
zig1seems to have the more correct behavior, as in each case I've hit, the error seems applicable.Expected Behavior
zig1and the stage3 compiler to agree on when things are never mutated.