diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index 11b7e14c48649b..0bc09d26a9eee3 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -1051,6 +1051,11 @@ fn (mut c Checker) infer_fn_generic_types(func &ast.Fn, mut node ast.CallExpr) { typ = typ.set_nr_muls(0) } } + if arg_elem_sym.kind == .any { + c.error('could not infer generic type `${gt_name}` in call to `${func.name}`', + node.pos) + return + } break } } diff --git a/vlib/v/checker/tests/generic_fn_array_param_not_infer_type_err.out b/vlib/v/checker/tests/generic_fn_array_param_not_infer_type_err.out new file mode 100644 index 00000000000000..e1607f489f8c13 --- /dev/null +++ b/vlib/v/checker/tests/generic_fn_array_param_not_infer_type_err.out @@ -0,0 +1,5 @@ +vlib/v/checker/tests/generic_fn_array_param_not_infer_type_err.vv:3:8: error: could not infer generic type `T` in call to `arrays.sum` + 1 | import arrays + 2 | + 3 | arrays.sum([]) or { panic(err) } + | ~~~~~~~ diff --git a/vlib/v/checker/tests/generic_fn_array_param_not_infer_type_err.vv b/vlib/v/checker/tests/generic_fn_array_param_not_infer_type_err.vv new file mode 100644 index 00000000000000..d566df370c3c5c --- /dev/null +++ b/vlib/v/checker/tests/generic_fn_array_param_not_infer_type_err.vv @@ -0,0 +1,3 @@ +import arrays + +arrays.sum([]) or { panic(err) }