Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Dec 16, 2024
1 parent 52b6469 commit 9ba615e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -7029,6 +7029,11 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type ast.Ty
// Now that option types are distinct we need a cast here
if g.fn_decl == unsafe { nil } || g.fn_decl.return_type == ast.void_type {
g.writeln('\treturn;')
} else if g.fn_decl.return_type.clear_option_and_result() == return_type.clear_option_and_result() {
styp := g.styp(g.fn_decl.return_type).replace('*', '_ptr')
err_obj := g.new_tmp_var()
g.writeln2('\t${styp} ${err_obj};', '\tmemcpy(&${err_obj}, &${cvar_name}, sizeof(_option));')
g.writeln('\treturn ${err_obj};')
} else {
g.write('\treturn ')
g.gen_option_error(g.fn_decl.return_type, ast.None{})
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/tests/options/option_ptr_unwrap_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn new_linked_list[T]() &LinkedList[T] {
return &LinkedList[T]{}
}

fn (mut li LinkedList[T]) add[T](data T) {
fn (mut li LinkedList[T]) add[T](data T) ? {
mut node := &Node[T]{data, none, none}

if li.head == none {
Expand Down

0 comments on commit 9ba615e

Please sign in to comment.