mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix if_expr of multi-stmts optional (#9039)
This commit is contained in:
parent
dc04c3196b
commit
65900e55e3
@ -937,6 +937,9 @@ fn (mut g Gen) stmts_with_tmp_var(stmts []ast.Stmt, tmp_var string) {
|
||||
}
|
||||
} else {
|
||||
g.stmt(stmt)
|
||||
if g.inside_if_optional && stmt is ast.ExprStmt {
|
||||
g.writeln(';')
|
||||
}
|
||||
}
|
||||
g.skip_stmt_pos = false
|
||||
if g.inside_ternary > 0 && i < stmts.len - 1 {
|
||||
|
@ -23,3 +23,23 @@ fn test_if_expr_of_optional() {
|
||||
println(a3)
|
||||
assert a3 == 2
|
||||
}
|
||||
|
||||
fn foo_complex() ?int {
|
||||
a := 2
|
||||
return if a > 1 {
|
||||
mut b := 1
|
||||
b *= 10
|
||||
b
|
||||
} else {
|
||||
mut c := 0
|
||||
c += 2
|
||||
println(c)
|
||||
none
|
||||
}
|
||||
}
|
||||
|
||||
fn test_if_expr_of_optional_complex() {
|
||||
a := foo_complex() or { panic('error') }
|
||||
println(a)
|
||||
assert a == 10
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user