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

checker: fix result call or_block with multi-statements (fix #21504) #21717

Closed yuyi98 closed 5 days ago

yuyi98 commented 5 days ago

This PR fix result call or_block with multi-statements (fix #21504).

fn str_ret_fn(str string) string {
    return str
}

fn foo(str string) !string {
    if str.contains('foo') {
        return str
    }
    return error('error')
}

fn main() {
    var := foo('bar') or {
        foo_var := str_ret_fn('foo')
        if foo_var == 'foo' {
            foo(foo_var) or {
                eprintln(err)
                exit(1)
            }
        } else {
            eprintln(err)
            exit(1)
        }
    }

    println(var)
    assert var == 'foo'
}

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