Merge pull request 'compiler: fix missing "local variable is never mutated" error' (#31534) from variable-not-mutated into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31534
This commit is contained in:
mlugg
2026-03-16 00:05:30 +01:00
7 changed files with 95 additions and 38 deletions
@@ -18,6 +18,16 @@ fn entry2() void {
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
@@ -26,3 +36,7 @@ fn foo(_: u32) void {}
// :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'