Skip to content

Commit a58dde4

Browse files
authored
cgen: fix error for optional multi return (#13959)
1 parent c9dcdf6 commit a58dde4

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

vlib/v/gen/c/assign.v

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ fn (mut g Gen) gen_multi_return_assign(node &ast.AssignStmt, return_type ast.Typ
471471
// TODO Handle in if_expr
472472
is_opt := return_type.has_flag(.optional)
473473
mr_var_name := 'mr_$node.pos.pos'
474-
mr_styp := g.typ(return_type)
474+
mr_styp := g.typ(return_type.clear_flag(.optional))
475475
g.write('$mr_styp $mr_var_name = ')
476476
g.expr(node.right[0])
477477
g.writeln(';')
@@ -505,9 +505,9 @@ fn (mut g Gen) gen_multi_return_assign(node &ast.AssignStmt, return_type ast.Typ
505505
if is_opt {
506506
mr_base_styp := g.base_type(return_type)
507507
if is_auto_heap {
508-
g.writeln('HEAP${noscan}($mr_base_styp, *($mr_base_styp*)${mr_var_name}.data).arg$i) });')
508+
g.writeln('HEAP${noscan}($mr_base_styp, ${mr_var_name}.arg$i) });')
509509
} else {
510-
g.writeln('(*($mr_base_styp*)${mr_var_name}.data).arg$i });')
510+
g.writeln('${mr_var_name}.arg$i });')
511511
}
512512
} else {
513513
if is_auto_heap {
@@ -520,9 +520,9 @@ fn (mut g Gen) gen_multi_return_assign(node &ast.AssignStmt, return_type ast.Typ
520520
if is_opt {
521521
mr_base_styp := g.base_type(return_type)
522522
if is_auto_heap {
523-
g.writeln(' = HEAP${noscan}($mr_base_styp, *($mr_base_styp*)${mr_var_name}.data).arg$i);')
523+
g.writeln(' = HEAP${noscan}($mr_base_styp, ${mr_var_name}.arg$i);')
524524
} else {
525-
g.writeln(' = (*($mr_base_styp*)${mr_var_name}.data).arg$i;')
525+
g.writeln(' = ${mr_var_name}.arg$i;')
526526
}
527527
} else {
528528
if is_auto_heap {

vlib/v/gen/c/fn.v

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,6 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
695695
unwrapped_styp := g.typ(unwrapped_typ)
696696
if unwrapped_typ == ast.void_type {
697697
g.write('\n $cur_line')
698-
} else if g.table.sym(node.return_type).kind == .multi_return {
699-
g.write('\n $cur_line $tmp_opt /*U*/')
700698
} else {
701699
if !g.inside_const_optional {
702700
g.write('\n $cur_line (*($unwrapped_styp*)${tmp_opt}.data)')
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn tuple() ?(int, int) {
2+
return 1, 2
3+
}
4+
5+
fn test_optional_multi_return() ? {
6+
println(tuple() ?)
7+
a, b := tuple() ?
8+
assert a == 1
9+
assert b == 2
10+
}

0 commit comments

Comments
 (0)