Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Sep 22, 2024
1 parent 7203317 commit 003fbff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/gen/c/assign.v
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
}
fn_name := c_fn_name(g.get_ternary_name(ident.name))

if val_type.has_flag(.option) && val in [ast.CastExpr, ast.SelectorExpr] {
if val_type.has_flag(.option) {
ret_styp := g.typ(g.unwrap_generic(val_type))
g.write('${ret_styp} ${fn_name}')
} else {
Expand Down
8 changes: 8 additions & 0 deletions vlib/v/tests/options/option_fntype_assign_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ fn find_func(name string) ?DataFn {
return a
}

fn find_func2(name string) ?DataFn {
a := if name == 'vlang' { ?DataFn(which_lang) } else { none }
return a
}

fn test_main() {
if a := find_func('foo') {
assert a('bar') == 'bar'
}
if b := find_func('foo') {
assert b('bar') == 'bar'
}
}

0 comments on commit 003fbff

Please sign in to comment.