Skip to content

Commit

Permalink
cgen: fix missing call to a function returning option, when called in…
Browse files Browse the repository at this point in the history
…side a print (fix #21616) (#21623)
  • Loading branch information
felipensp authored Jun 1, 2024
1 parent bb3505f commit ca55da6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions vlib/v/gen/c/str.v
Original file line number Diff line number Diff line change
Expand Up @@ -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("<none>")')
} else if sym.kind == .enum_ {
if expr !is ast.EnumVal {
Expand Down
10 changes: 10 additions & 0 deletions vlib/v/tests/print_void_ret_test.v
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit ca55da6

Please sign in to comment.