Skip to content

Commit c590c82

Browse files
authored
cgen: fix fn with optional of multi_return (#16046)
1 parent 7f2d731 commit c590c82

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

vlib/v/gen/c/cgen.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4166,11 +4166,11 @@ fn (mut g Gen) cast_expr(node ast.CastExpr) {
41664166
}
41674167

41684168
fn (mut g Gen) concat_expr(node ast.ConcatExpr) {
4169-
mut styp := g.typ(node.return_type)
4169+
mut styp := g.typ(node.return_type.clear_flag(.optional).clear_flag(.result))
41704170
if g.inside_return {
4171-
styp = g.typ(g.fn_decl.return_type)
4171+
styp = g.typ(g.fn_decl.return_type.clear_flag(.optional).clear_flag(.result))
41724172
} else if g.inside_or_block {
4173-
styp = g.typ(g.or_expr_return_type)
4173+
styp = g.typ(g.or_expr_return_type.clear_flag(.optional).clear_flag(.result))
41744174
}
41754175
sym := g.table.sym(node.return_type)
41764176
is_multi := sym.kind == .multi_return
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
struct Aa {
2+
x string
3+
}
4+
5+
struct Bb {
6+
a int
7+
}
8+
9+
fn give(succ Aa) ?(Aa, Bb) {
10+
return match succ.x {
11+
'x' {
12+
succ, Bb{}
13+
}
14+
else {
15+
error('nok')
16+
}
17+
}
18+
}
19+
20+
fn test_fn_with_opt_of_multi_return() {
21+
res, _ := give(Aa{ x: 'x' }) or { panic('got unexpected err') }
22+
23+
assert res.x == 'x'
24+
println('success')
25+
}

0 commit comments

Comments
 (0)