-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.Tokenization, parsing, AstGen, Sema, and Liveness.regressionIt worked in a previous version of Zig, but stopped working.It worked in a previous version of Zig, but stopped working.
Milestone
Description
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:
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.Tokenization, parsing, AstGen, Sema, and Liveness.regressionIt worked in a previous version of Zig, but stopped working.It worked in a previous version of Zig, but stopped working.