1
0
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:
Felipe Pena 2023-01-30 06:27:17 -03:00 committed by GitHub
parent a489417484
commit 11f734296f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

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

View 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]
}