Skip to content

Commit

Permalink
cgen: fix generated code for fixed array cast (fix #20454) (#20480)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jan 12, 2024
1 parent b120c10 commit bcd77ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vlib/v/gen/c/array.v
Expand Up @@ -146,6 +146,10 @@ fn (mut g Gen) fixed_array_init(node ast.ArrayInit, array_type Type, var_name st
ret_typ := g.typ(node.typ)
g.write('${ret_typ} ${tmp_var} = ')
}
if g.inside_struct_init && g.inside_cast {
ret_typ := g.typ(node.typ)
g.write('(${ret_typ})')
}
g.write('{')
if node.has_val {
tmp_inside_array := g.inside_array_item
Expand Down
14 changes: 14 additions & 0 deletions vlib/v/tests/cast_fixed_array_to_ptr_ptr_test.v
@@ -0,0 +1,14 @@
struct Foo {
bar &&char
}

fn test_main() {
foo := Foo{
bar: unsafe {
&&char(['a', 'b', nil]!)
}
}
println(foo)
a := unsafe { cstring_to_vstring(*foo.bar) }
assert a == 'a'
}

0 comments on commit bcd77ed

Please sign in to comment.