mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix if_expr with array methods cond (#10786)
This commit is contained in:
parent
78a41969f6
commit
ed78e638b3
@ -4522,7 +4522,10 @@ fn (mut g Gen) if_expr(node ast.IfExpr) {
|
||||
if needs_tmp_var {
|
||||
g.stmts_with_tmp_var(branch.stmts, tmp)
|
||||
} else {
|
||||
// restore if_expr stmt header pos
|
||||
stmt_pos := g.nth_stmt_pos(0)
|
||||
g.stmts(branch.stmts)
|
||||
g.stmt_path_pos << stmt_pos
|
||||
}
|
||||
}
|
||||
g.writeln('}')
|
||||
|
@ -199,3 +199,17 @@ fn min<T>(a T, b T) T {
|
||||
fn test_if_expr_with_fn_generic() {
|
||||
assert min(42, 13) == 13
|
||||
}
|
||||
|
||||
fn test_if_expr_with_complex_array_methods() {
|
||||
mut ret := []string{}
|
||||
entries := ['a', 'b', 'c']
|
||||
|
||||
if false {
|
||||
ret = entries.map(it.capitalize())
|
||||
} else if entries.any(it == 'a') {
|
||||
ret = entries.map(it)
|
||||
}
|
||||
|
||||
println(ret)
|
||||
assert ret == ['a', 'b', 'c']
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user