mirror of
https://github.com/vlang/v.git
synced 2025-09-19 04:17:46 -04:00
cgen: fix multi return with option type (#24144)
This commit is contained in:
parent
1e6fdbf815
commit
a69b0b7224
@ -5517,10 +5517,9 @@ fn (mut g Gen) concat_expr(node ast.ConcatExpr) {
|
|||||||
g.write('(${styp}){')
|
g.write('(${styp}){')
|
||||||
for i, expr in node.vals {
|
for i, expr in node.vals {
|
||||||
g.write('.arg${i}=')
|
g.write('.arg${i}=')
|
||||||
if types[i].has_flag(.option) && expr.is_literal() {
|
expr_typ := g.get_expr_type(expr)
|
||||||
g.write('{.data=')
|
if expr_typ != ast.void_type && types[i].has_flag(.option) {
|
||||||
g.expr(expr)
|
g.expr_with_opt(expr, expr_typ, types[i])
|
||||||
g.write('}')
|
|
||||||
} else {
|
} else {
|
||||||
old_left_is_opt := g.left_is_opt
|
old_left_is_opt := g.left_is_opt
|
||||||
g.left_is_opt = true
|
g.left_is_opt = true
|
||||||
@ -5942,7 +5941,7 @@ fn (mut g Gen) return_stmt(node ast.Return) {
|
|||||||
multi_unpack += g.go_before_last_stmt()
|
multi_unpack += g.go_before_last_stmt()
|
||||||
g.write(line)
|
g.write(line)
|
||||||
expr_styp := g.base_type(call_expr.return_type)
|
expr_styp := g.base_type(call_expr.return_type)
|
||||||
tmp = ('(*(${expr_styp}*)${tmp}.data)')
|
tmp = '(*(${expr_styp}*)${tmp}.data)'
|
||||||
}
|
}
|
||||||
expr_types := expr_sym.mr_info().types
|
expr_types := expr_sym.mr_info().types
|
||||||
for j, _ in expr_types {
|
for j, _ in expr_types {
|
||||||
|
@ -472,6 +472,21 @@ fn (mut g Gen) get_expr_type(cond ast.Expr) ast.Type {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ast.IntegerLiteral {
|
||||||
|
return ast.int_type
|
||||||
|
}
|
||||||
|
ast.BoolLiteral {
|
||||||
|
return ast.bool_type
|
||||||
|
}
|
||||||
|
ast.StringLiteral {
|
||||||
|
return ast.string_type
|
||||||
|
}
|
||||||
|
ast.CharLiteral {
|
||||||
|
return ast.char_type
|
||||||
|
}
|
||||||
|
ast.FloatLiteral {
|
||||||
|
return ast.f64_type
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
return ast.void_type
|
return ast.void_type
|
||||||
}
|
}
|
||||||
|
10
vlib/v/tests/options/option_multi_return_opt_test.v
Normal file
10
vlib/v/tests/options/option_multi_return_opt_test.v
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
fn fails(i int) !(int, ?int) {
|
||||||
|
return error('fails')
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
a2, b2 := fails(2) or { 22, 22 }
|
||||||
|
c2 := b2? as int
|
||||||
|
assert b2 != none
|
||||||
|
assert a2 == c2
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user