jakt
jakt copied to clipboard
Able to take mutable slice of immutable array
The following code is possible:
function main() {
let foo = [1, 2, 3, 4]
mut slice = foo[1..2]
slice[0] = 5
println("Foo is {} and the slice is {}", foo, slice)
}
This compiles and prints Foo is [1, 5, 3, 4] and the slice is [5]
I don't know whether this is a design choice that I can't find documentation for, but it really feels like a bug to me.
It is the same with classes.
class Test {
public a: i64
}
function main() {
let a = Test(a: 1)
mut b = a
b.a++
println("{}", a)
}
With the binding being immutable but not the object itself.