Skip to content

Commit

Permalink
cgen: fix C code, generated for generic option fixed array return type (
Browse files Browse the repository at this point in the history
fix #20465) (#20479)
  • Loading branch information
felipensp committed Jan 11, 2024
1 parent 341e79f commit 781d97d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vlib/v/gen/c/fn.v
Expand Up @@ -228,7 +228,8 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
mut type_name := g.typ(g.unwrap_generic(node.return_type))

ret_sym := g.table.sym(g.unwrap_generic(node.return_type))
if node.return_type.has_flag(.generic) && ret_sym.kind == .array_fixed {
if node.return_type.has_flag(.generic) && !node.return_type.has_flag(.option)
&& ret_sym.kind == .array_fixed {
type_name = '_v_${type_name}'
} else if ret_sym.kind == .alias && !node.return_type.has_flag(.option) {
unalias_typ := g.table.unaliased_type(node.return_type)
Expand Down
10 changes: 10 additions & 0 deletions vlib/v/tests/fixed_array_generic_ret_test.v
@@ -0,0 +1,10 @@
fn example[T]() ?T {
return T{}
}

fn test_main() {
dump(example[[1]int]())

a := example[[1]int]()
assert a? == [0]!
}

0 comments on commit 781d97d

Please sign in to comment.