diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 295b89c518..1340724600 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -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 { diff --git a/vlib/v/tests/generics_array_builtin_method_call_test.v b/vlib/v/tests/generics_array_builtin_method_call_test.v new file mode 100644 index 0000000000..b6be6ded5e --- /dev/null +++ b/vlib/v/tests/generics_array_builtin_method_call_test.v @@ -0,0 +1,32 @@ +struct Container { +mut: + items []T +} + +fn (mut c Container) pop() ?T { + return c.items.pop() +} + +struct Item { + data string + priority int +} + +fn test_generic_array_pop_call() { + mut a1 := Container{ + 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{ + items: [item1, item2] + } + println(a2) + ret2 := a2.pop() or { Item{} } + assert ret2 == item2 +}