Files
zig/test/cases/compile_errors/var_never_mutated.zig
Matthew Lugg 827a96b1ef compiler: fix missing "local variable is never mutated" error
This regressed back in https://github.com/ziglang/zig/pull/25154. I
didn't get around to fixing it until now, so a few instances of the
warning snuck into the repo over the past few months, which were fixed
in the previous commit. The regression has not appeared in a tagged
release though, so this is not a breaking change in 0.16.0.

Resolves: https://codeberg.org/ziglang/zig/issues/31049
2026-03-15 18:24:32 +00:00

43 lines
837 B
Zig

fn entry0() void {
var a: u32 = 1 + 2;
_ = a;
}
fn entry1() void {
const a: u32 = 1;
const b: u32 = 2;
var c = a + b;
const d = c;
_ = d;
}
fn entry2() void {
var a: u32 = 123;
foo(a);
}
fn foo(_: u32) void {}
fn entry3() void {
var a: [1]u8 = .{0};
_ = a[0];
}
fn entry4() void {
var s: struct { a: u8 } = .{ .a = 0 };
_ = s.a;
}
// error
//
// :2:9: error: local variable is never mutated
// :2:9: note: consider using 'const'
// :9:9: error: local variable is never mutated
// :9:9: note: consider using 'const'
// :15:9: error: local variable is never mutated
// :15:9: note: consider using 'const'
// :22:9: error: local variable is never mutated
// :22:9: note: consider using 'const'
// :27:9: error: local variable is never mutated
// :27:9: note: consider using 'const'