mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix generic array clone (#17153)
This commit is contained in:
parent
a489417484
commit
11f734296f
@ -2232,7 +2232,11 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as
|
||||
if method_name == 'slice' && !c.is_builtin_mod {
|
||||
c.error('.slice() is a private method, use `x[start..end]` instead', node.pos)
|
||||
}
|
||||
array_info := left_sym.info as ast.Array
|
||||
array_info := if left_sym.info is ast.Array {
|
||||
left_sym.info as ast.Array
|
||||
} else {
|
||||
c.table.sym(c.unwrap_generic(left_type)).info as ast.Array
|
||||
}
|
||||
elem_typ = array_info.elem_type
|
||||
if method_name in ['filter', 'map', 'any', 'all'] {
|
||||
// position of `it` doesn't matter
|
||||
|
8
vlib/v/tests/generic_array_clone_test.v
Normal file
8
vlib/v/tests/generic_array_clone_test.v
Normal file
@ -0,0 +1,8 @@
|
||||
fn test_main() {
|
||||
encode([]int{len: 5, init: 5})
|
||||
}
|
||||
|
||||
fn encode[U](val U) {
|
||||
new_val := val.clone()
|
||||
assert new_val == [5, 5, 5, 5, 5]
|
||||
}
|
Loading…
Reference in New Issue
Block a user