zls icon indicating copy to clipboard operation
zls copied to clipboard

LSP does not show an error when mutating a const

Open Hcode00 opened this issue 1 year ago • 0 comments

Example:

test "const pointers" {
    const x: u8 = 1;
    x += 1;  // does not give any error 
    const y = &x;
    y.* += 1;  // does not give any error 
}

until you compile it you get this error:

error: cannot assign to constant
    y.* += 1;
    ~~~~^~~~
error: cannot assign to constant
    x += 1;
    ~~^~~~

Hcode00 avatar Jul 18 '24 20:07 Hcode00