sophiajt / june

MIT License
813 stars 31 forks source link

Breaking Immutability #70

Closed JoanaBLate closed 1 month ago

JoanaBLate commented 1 month ago

// commit fad3da8ed46b6168a3535f18fbf96506dcd782f9

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 commented 1 month ago

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

JoanaBLate commented 1 month ago

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.