Skip to content

Commit

Permalink
cgen: fix codegen for array's .grow_cap and .grow_len methods for gen…
Browse files Browse the repository at this point in the history
…eric arrays (fix #23566) (#23568)
  • Loading branch information
felipensp authored Jan 25, 2025
1 parent 991ec1f commit fac8bb8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions vlib/v/gen/c/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,13 @@ fn (mut g Gen) gen_array_method_call(node ast.CallExpr, left_type ast.Type, left
}
g.write(')')
}
'grow_cap', 'grow_len' {
g.write('array_${node.name}(')
g.gen_arg_from_type(left_type, node.left)
g.write(', ')
g.expr(node.args[0].expr)
g.write(')')
}
'first', 'last', 'pop' {
mut noscan := ''
array_info := left_sym.info as ast.Array
Expand Down
9 changes: 9 additions & 0 deletions vlib/v/tests/builtin_arrays/array_grow_cap_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn grow[T](mut arr []T) {
arr.grow_cap(10)
unsafe { arr.grow_len(10) }
}

fn test_main() {
mut arr := []int{}
grow(mut arr)
}

0 comments on commit fac8bb8

Please sign in to comment.