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 infix expr and/or operate unnecessary evaluate (fix #21590) #21740

Closed yuyi98 closed 2 days ago

yuyi98 commented 2 days ago

This PR fix infix expr and/or operate unnecessary evaluate (fix #21590).

fn f(s string) !int {
    if s == '' {
        return error('invalid s')
    }
    return s.len
}

fn main() {
    v := ''
    x := v != 'xyz' || f(v)! < f('abc')!
    dump(x)
    assert x

    y := v == 'xyz' && f(v)! < f('abc')!
    dump(y)
    assert !y
}

PS D:\Test\v\tt1> v run .
[.\\tt1.v:11] x: true
[.\\tt1.v:15] y: false