Skip to content

Commit

Permalink
checker: error if cannot generic infer type from empty array ([])
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 committed Nov 17, 2024
1 parent e6c6c24 commit 1a2884c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vlib/v/checker/check_types.v
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,10 @@ fn (mut c Checker) infer_fn_generic_types(func &ast.Fn, mut node ast.CallExpr) {
&& param_elem_sym.name !in c.table.cur_fn.generic_names {
arg_elem_typ, param_elem_typ = arg_elem_sym.info.elem_type, param_elem_sym.info.elem_type
arg_elem_sym, param_elem_sym = c.table.sym(arg_elem_typ), c.table.sym(param_elem_typ)
} else if arg.expr is ast.ArrayInit && arg.expr.exprs.len == 0 {
c.error('could not infer generic type `${gt_name}` in call to `${func.name}`',
node.pos)
return
} else {
if param_elem_sym.name == gt_name {
typ = arg_elem_typ
Expand Down
Original file line number Diff line number Diff line change
@@ -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) }
| ~~~~~~~
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import arrays

arrays.sum([]) or { panic(err) }

0 comments on commit 1a2884c

Please sign in to comment.