rune
rune copied to clipboard
Incorrect error when trying to mutate constants.
Found this while trying some stuff on the playground over lunch...
const FOOBAR = 1;
pub fn main() {
FOOBAR = 1;
}
gives the errors:
error: compile error
┌─ entry:4:5
│
4 │ FOOBAR = 1;
│ ^^^^^^^^^^ no local variable `FOOBAR`
warning: warning
┌─ entry:1:1
│
1 │ const FOOBAR = 1;
│ ^^^^^^^^^^^^^^^^ not used
https://rune-rs.github.io/play/?c=Y29uc3QgRk9PQkFSID0gMTsKCnB1YiBmbiBtYWluKCkgewogICAgRk9PQkFSID0gMTsKfQo%3D
So I'm bug triaging right now. Since mutating a constant shouldn't be possible, what is the preferred solution here? Is it simply a matter of improving the compilation so that it queries for any items which also matches the left hand side of an assignment and raises a different more descriptive error which says that FOOBAR
is used but incorrectly:
error: compile error
┌─ entry:4:5
│
4 │ FOOBAR = 1;
│ ^^^^^^^^^^ cannot assign to `const FOOBAR`
I think that'd be a much better error message!