0 issues 1 contributor 4 branches 0 releases
Additions: 26 Deletions: 0 View patch
1 info := param_sym.array_info()
2 c.expected_type = info.elem_type
3 }
4+ typ := c.expr(call_arg.expr)
5+ if i == node.args.len - 1 && c.table.sym(typ).kind == .array
6+ && call_arg.expr !is ast.ArrayDecompose && !param.typ.has_flag(.generic)
7+ && c.expected_type != typ {
8+ styp := c.table.type_to_str(typ)
9+ elem_styp := c.table.type_to_str(c.expected_type)
10+ c.error('to pass `$call_arg.expr` ($styp) to `$func.name` (which accepts type `...$elem_styp`), use `...$call_arg.expr`',
11+ node.pos)
12+ }
13 } else {
14 c.expected_type = param.typ
15 }
16
1new file mode 100644
2+vlib/v/checker/tests/fn_variadic_arg_err.vv:5:2: error: to pass `a` ([]u8) to `varg_fn_a` (which accepts type `...u8`), use `...a`
3+ 3 | fn main() {
4+ 4 | a := [u8(1), 2, 3, 4]
5+ 5 | varg_fn_a(a)
6+ | ~~~~~~~~~~~~
7+ 6 | }
8+ 7 |
9
1new file mode 100644
2+module main
3+
4+fn main() {
5+ a := [u8(1), 2, 3, 4]
6+ varg_fn_a(a)
7+}
8+
9+fn varg_fn_a(b ...u8) {
10+ println(b)
11+}
12