1
0
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:
Felipe Pena 2023-05-14 07:50:04 -03:00 committed by GitHub
parent bfb5a770b2
commit d4072bfc22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -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 {

View 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'
}