Skip to content

Commit

Permalink
cgen: fix codegen for assign from unsafe fn returning fixed array (fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Jan 22, 2025
1 parent 45b79df commit b036a6a
Show file tree
Hide file tree
Showing 2 changed files with 11 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 @@ -471,7 +471,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
&& (val in [ast.Ident, ast.IndexExpr, ast.CallExpr, ast.SelectorExpr, ast.DumpExpr, ast.InfixExpr]
|| (val is ast.CastExpr && val.expr !is ast.ArrayInit)
|| (val is ast.PrefixExpr && val.op == .arrow)
|| (val is ast.UnsafeExpr && val.expr in [ast.SelectorExpr, ast.Ident]))
|| (val is ast.UnsafeExpr && val.expr in [ast.SelectorExpr, ast.Ident, ast.CallExpr]))
g.is_assign_lhs = true
g.assign_op = node.op

Expand Down
10 changes: 10 additions & 0 deletions vlib/v/tests/builtin_arrays/array_fixed_from_unsafe_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@[unsafe]
fn test() [5]int {
return [5]int{}
}

fn test_main() {
foo := unsafe { test() }
assert foo.len == 5
assert foo == unsafe { test() }
}

0 comments on commit b036a6a

Please sign in to comment.