1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: fix generic array builtin method call (#12957)

This commit is contained in:
yuyi 2021-12-24 20:42:23 +08:00 committed by GitHub
parent a83786d867
commit d0ad79cd8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -931,7 +931,7 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
// TODO: remove this for actual methods, use only for compiler magic
// FIXME: Argument count != 1 will break these
if left_sym.kind == .array && method_name in array_builtin_methods {
return c.array_builtin_method_call(mut node, left_type, left_sym)
return c.array_builtin_method_call(mut node, left_type, c.table.sym(left_type))
} else if (left_sym.kind == .map || final_left_sym.kind == .map)
&& method_name in ['clone', 'keys', 'move', 'delete'] {
if left_sym.kind == .map {

View File

@ -0,0 +1,32 @@
struct Container<T> {
mut:
items []T
}
fn (mut c Container<T>) pop() ?T {
return c.items.pop()
}
struct Item {
data string
priority int
}
fn test_generic_array_pop_call() {
mut a1 := Container<int>{
items: [11, 22]
}
println(a1)
ret1 := a1.pop() or { 0 }
println(ret1)
assert ret1 == 22
item1 := Item{'a', 1}
item2 := Item{'b', 2}
mut a2 := Container<Item>{
items: [item1, item2]
}
println(a2)
ret2 := a2.pop() or { Item{} }
assert ret2 == item2
}