cgen: fix codegen for array's .grow_cap and .grow_len methods for generic arrays (fix #23566) (#23568)

This commit is contained in:
Felipe Pena 2025-01-25 01:58:58 -03:00 committed by GitHub
parent 991ec1f9d2
commit fac8bb8694
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View File

@ -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

View File

@ -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)
}