From bbfe293bb4c1eb59d86bd84c27126d26b7d5f17e Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sat, 1 Jun 2024 09:03:10 -0300 Subject: [PATCH] fix --- vlib/v/gen/c/str.v | 6 ++++++ vlib/v/tests/print_void_ret_test.v | 10 ++++++++++ 2 files changed, 16 insertions(+) create mode 100644 vlib/v/tests/print_void_ret_test.v diff --git a/vlib/v/gen/c/str.v b/vlib/v/gen/c/str.v index 4483b12e92df1d..c8f0f8ca997730 100644 --- a/vlib/v/gen/c/str.v +++ b/vlib/v/gen/c/str.v @@ -92,6 +92,12 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) { g.expr(expr) g.write(' ? _SLIT("true") : _SLIT("false")') } else if sym.kind == .none_ || typ == ast.void_type.set_flag(.option) { + if expr is ast.CallExpr { + stmt_str := g.go_before_last_stmt() + g.expr(expr) + g.writeln(';') + g.write(stmt_str) + } g.write('_SLIT("")') } else if sym.kind == .enum_ { if expr !is ast.EnumVal { diff --git a/vlib/v/tests/print_void_ret_test.v b/vlib/v/tests/print_void_ret_test.v new file mode 100644 index 00000000000000..a98ce5839cab9b --- /dev/null +++ b/vlib/v/tests/print_void_ret_test.v @@ -0,0 +1,10 @@ +fn foo(mut a &int) ? { + println('XXX') + a++ +} + +fn test_main() { + mut a := 1 + println(foo(mut &a)) + assert a == 2 +}