Skip to content

Commit 6520805

Browse files
authored
checker: correctly detect type, when prepending to generic array (fix #25585) (#25645)
1 parent 14072ce commit 6520805

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

vlib/v/checker/fn.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3335,7 +3335,8 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as
33353335
arg.expr.pos())
33363336
continue
33373337
}
3338-
} else if !c.check_types(base_arg_type, c.unwrap_generic(left_type)) {
3338+
} else if !c.check_types(base_arg_type, unwrapped_left_type)
3339+
&& !c.check_types(elem_typ, base_arg_type) {
33393340
c.error('cannot ${method_name} `${arg_sym.name}` to `${left_sym.name}`',
33403341
arg.expr.pos())
33413342
continue
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
struct Buffer[T] {
2+
size int
3+
mut:
4+
content []T
5+
}
6+
7+
pub fn create_buffer[T](size int) Buffer[T] {
8+
return Buffer[T]{
9+
size: size
10+
content: []T{}
11+
}
12+
}
13+
14+
pub fn (mut b Buffer[T]) write(value T) {
15+
b.content.prepend(value)
16+
}
17+
18+
fn test_main() {
19+
mut buffer := create_buffer[int](3)
20+
buffer.write(1)
21+
assert buffer.content[0] == 1
22+
}

0 commit comments

Comments
 (0)