mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix option with multi return assign (#18174)
This commit is contained in:
parent
bfb5a770b2
commit
d4072bfc22
@ -747,7 +747,10 @@ fn (mut g Gen) gen_multi_return_assign(node &ast.AssignStmt, return_type ast.Typ
|
|||||||
g.write(' = ${tmp_var};')
|
g.write(' = ${tmp_var};')
|
||||||
} else {
|
} else {
|
||||||
g.write('_option_ok(&(${base_typ}[]) { ${tmp_var} }, (${option_name}*)(&')
|
g.write('_option_ok(&(${base_typ}[]) { ${tmp_var} }, (${option_name}*)(&')
|
||||||
|
tmp_left_is_opt := g.left_is_opt
|
||||||
|
g.left_is_opt = true
|
||||||
g.expr(lx)
|
g.expr(lx)
|
||||||
|
g.left_is_opt = tmp_left_is_opt
|
||||||
g.writeln('), sizeof(${base_typ}));')
|
g.writeln('), sizeof(${base_typ}));')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
11
vlib/v/tests/option_multi_return_assign_test.v
Normal file
11
vlib/v/tests/option_multi_return_assign_test.v
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fn t() (string, string) {
|
||||||
|
return 'foo', 'bar'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
mut a := ?string(none)
|
||||||
|
mut b := ''
|
||||||
|
a, b = t()
|
||||||
|
assert a? == 'foo'
|
||||||
|
assert b == 'bar'
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user