mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix anon fn direct call with option (#18827)
This commit is contained in:
parent
921a2e1c2e
commit
1728e4c73e
@ -683,9 +683,12 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
|
|||||||
tmp_var := g.new_tmp_var()
|
tmp_var := g.new_tmp_var()
|
||||||
fn_type := g.fn_var_signature(node.left.decl.return_type, node.left.decl.params.map(it.typ),
|
fn_type := g.fn_var_signature(node.left.decl.return_type, node.left.decl.params.map(it.typ),
|
||||||
tmp_var)
|
tmp_var)
|
||||||
|
line := g.go_before_stmt(0).trim_space()
|
||||||
|
g.empty_line = true
|
||||||
g.write('${fn_type} = ')
|
g.write('${fn_type} = ')
|
||||||
g.expr(node.left)
|
g.expr(node.left)
|
||||||
g.writeln(';')
|
g.writeln(';')
|
||||||
|
g.write(line)
|
||||||
g.write(tmp_var)
|
g.write(tmp_var)
|
||||||
} else if node.or_block.kind == .absent {
|
} else if node.or_block.kind == .absent {
|
||||||
g.expr(node.left)
|
g.expr(node.left)
|
||||||
|
17
vlib/v/tests/anon_fn_direct_call_with_option_test.v
Normal file
17
vlib/v/tests/anon_fn_direct_call_with_option_test.v
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
fn test_anon_fn_direct_call_with_option() {
|
||||||
|
z := true
|
||||||
|
a := fn [z] () ?int {
|
||||||
|
match z {
|
||||||
|
true { return 1 }
|
||||||
|
else { return none }
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
b := a or {
|
||||||
|
println('failed')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
println('b: ${b}')
|
||||||
|
println(a)
|
||||||
|
assert b == 1
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user