Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Breaking Immutability #70

Closed
JoanaBLate opened this issue May 10, 2024 · 2 comments
Closed

Breaking Immutability #70

JoanaBLate opened this issue May 10, 2024 · 2 comments

Comments

@JoanaBLate
Copy link

// commit fad3da8

struct Stats {
    age: i64
}

struct Employee {
    stats: Stats
}

fun main() {
    mut employee = new Employee(stats: new Stats(age: 100))
    let employee2 = new Employee(stats: new Stats(age: 200))

    // employee2.stats.age = 33 // error: variable is not mutable
    
    employee.stats = employee2.stats
    employee.stats.age = 33

    println(employee.stats.age)
    println(employee2.stats.age) // outputs 33 // immutable employee2 has CHANGED!
}
@sophiajt
Copy link
Owner

You're using aliases, so this is expected. It's the binding that is immutable, not the value underneath it.

@JoanaBLate
Copy link
Author

You're using aliases, so this is expected. It's the binding that is immutable, not the value underneath it.

I see. Just as a personal feedback: I don't feel this behavior is safe.

Thanks.

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

No branches or pull requests

2 participants