Skip to content

Commit

Permalink
cgen: fix returning option call in non-option fn
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Mar 2, 2024
1 parent 065e5e2 commit 2d3a0fe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -6715,6 +6715,7 @@ fn (mut g Gen) gen_or_block_stmts(cvar_name string, cast_typ string, stmts []ast
if !is_array_fixed {
if g.inside_return && !g.inside_struct_init
&& expr_stmt.expr is ast.CallExpr
&& g.cur_fn.return_type.has_option_or_result()
&& return_type.has_option_or_result()
&& expr_stmt.expr.or_block.kind == .absent {
g.write('${cvar_name} = ')
Expand Down
11 changes: 11 additions & 0 deletions vlib/v/tests/return_option_call_in_non_option_fn_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import rand

pub fn random_number() i64 {
return rand.i64_in_range(111111, 999999) or { rand.i64() }
}

fn test_return_option_call_in_non_option_fn() {
ret := random_number()
println(ret)
assert true
}

0 comments on commit 2d3a0fe

Please sign in to comment.