Skip to content

Commit 11f7342

Browse files
authored
checker: fix generic array clone (#17153)
1 parent a489417 commit 11f7342

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

vlib/v/checker/fn.v

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2232,7 +2232,11 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as
22322232
if method_name == 'slice' && !c.is_builtin_mod {
22332233
c.error('.slice() is a private method, use `x[start..end]` instead', node.pos)
22342234
}
2235-
array_info := left_sym.info as ast.Array
2235+
array_info := if left_sym.info is ast.Array {
2236+
left_sym.info as ast.Array
2237+
} else {
2238+
c.table.sym(c.unwrap_generic(left_type)).info as ast.Array
2239+
}
22362240
elem_typ = array_info.elem_type
22372241
if method_name in ['filter', 'map', 'any', 'all'] {
22382242
// position of `it` doesn't matter
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn test_main() {
2+
encode([]int{len: 5, init: 5})
3+
}
4+
5+
fn encode[U](val U) {
6+
new_val := val.clone()
7+
assert new_val == [5, 5, 5, 5, 5]
8+
}

0 commit comments

Comments
 (0)