vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.5k stars 2.15k forks source link

cgen: fix fn call with mut reference args (fix #21265) #21719

Closed yuyi98 closed 5 days ago

yuyi98 commented 5 days ago

This PR fix fn call with mut reference args (fix #21265).

@[heap]
struct Client {
mut:
    next &Client = unsafe { nil }
    prev &Client = unsafe { nil }
}

fn init_vm1(mut head &Client) {
    for c := head; c; c = c.next {
    }
}

fn init_vm2(mut head &Client) {
    for c := head; c == unsafe { nil }; c = c.next {
    }
}

fn main() {
    mut head := &Client{}
    init_vm1(mut head)
    init_vm2(mut head)
    assert true
}

PS D:\Test\v\tt1> v run .