sophiajt / june

MIT License
803 stars 31 forks source link

Mutability compatibility issue on call-site vs args #48

Open amanjeev opened 6 months ago

amanjeev commented 6 months ago

Problem code

fun main() {
    fib(0, 1, 10)
}

fun fib(mut first: i64, mut second: i64, mut limit: i64) {
    println(first)
    println(second)

    mut next = first + second
    first = second
    second = next
    limit -= 1

    fib(first, second, limit)
}

Output

───┬─ main/main.june:2:9
 1 │ fun main() {
 2 │     fib(0, 1, 10)
   │         ╍ error: argument to function needs to be mutable
 3 │ }
───┴─

Expected output

No error, the call site should just pass integers and fib should take care of the mutability.