From 15e0802e8873c106731958ba4c4030d773cf475c Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 10 Aug 2025 08:03:04 -0300 Subject: [PATCH] cgen: fix codegen for option void fn return block unwrap (fix #25074) (#25082) --- vlib/v/gen/c/cgen.v | 2 +- vlib/v/tests/options/option_or_expr_dump_test.v | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/options/option_or_expr_dump_test.v diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 2972cfbd3..2c9f8acc7 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -7106,7 +7106,7 @@ fn (mut g Gen) gen_or_block_stmts(cvar_name string, cast_typ string, stmts []ast g.writeln(' }, (${option_name}*)&${cvar_name}, sizeof(${cast_typ}));') g.indent-- return - } else { + } else if return_type.clear_option_and_result() != ast.void_type { g.write('*(${cast_typ}*) ${cvar_name}${tmp_op}data = ') } } diff --git a/vlib/v/tests/options/option_or_expr_dump_test.v b/vlib/v/tests/options/option_or_expr_dump_test.v new file mode 100644 index 000000000..34fd65a64 --- /dev/null +++ b/vlib/v/tests/options/option_or_expr_dump_test.v @@ -0,0 +1,8 @@ +fn f() ? { + println('hello') + return none +} + +fn test_main() { + f() or { dump(err) } +} -- 2.39.5