diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 7789d373ab..ff18c04f2e 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -5517,10 +5517,9 @@ fn (mut g Gen) concat_expr(node ast.ConcatExpr) { g.write('(${styp}){') for i, expr in node.vals { g.write('.arg${i}=') - if types[i].has_flag(.option) && expr.is_literal() { - g.write('{.data=') - g.expr(expr) - g.write('}') + expr_typ := g.get_expr_type(expr) + if expr_typ != ast.void_type && types[i].has_flag(.option) { + g.expr_with_opt(expr, expr_typ, types[i]) } else { old_left_is_opt := g.left_is_opt 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() g.write(line) 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 for j, _ in expr_types { diff --git a/vlib/v/gen/c/comptime.v b/vlib/v/gen/c/comptime.v index 9fdc136366..188c4fd5c8 100644 --- a/vlib/v/gen/c/comptime.v +++ b/vlib/v/gen/c/comptime.v @@ -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 { return ast.void_type } diff --git a/vlib/v/tests/options/option_multi_return_opt_test.v b/vlib/v/tests/options/option_multi_return_opt_test.v new file mode 100644 index 0000000000..9d3d3e5647 --- /dev/null +++ b/vlib/v/tests/options/option_multi_return_opt_test.v @@ -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 +}