Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Able to take mutable slice of immutable array #1157

Open
thislooksfun opened this issue Sep 5, 2022 · 1 comment
Open

Able to take mutable slice of immutable array #1157

thislooksfun opened this issue Sep 5, 2022 · 1 comment

Comments

@thislooksfun
Copy link
Contributor

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.

@robryanx
Copy link
Contributor

robryanx commented Sep 8, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants