checker: check fn_variadic with array_decompose (#8894)
parent
0029d3ca76
commit
7a6fd359d0
|
@ -1921,6 +1921,11 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
|
|||
} else {
|
||||
f.params[i]
|
||||
}
|
||||
if f.is_variadic && call_arg.expr is ast.ArrayDecompose {
|
||||
if i > f.params.len - 1 {
|
||||
c.error('too many arguments in call to `$f.name`', call_expr.pos)
|
||||
}
|
||||
}
|
||||
c.expected_type = arg.typ
|
||||
typ := c.expr(call_arg.expr)
|
||||
call_expr.args[i].typ = typ
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
vlib/v/checker/tests/function_variadic_arg_array_decompose.vv:11:10: error: too many arguments in call to `sum`
|
||||
9 | fn main() {
|
||||
10 | b := [5, 6, 7]
|
||||
11 | println(sum(1, 2, ...b))
|
||||
| ~~~~~~~~~~~~~~~
|
||||
12 | }
|
|
@ -0,0 +1,12 @@
|
|||
fn sum(a ...int) int {
|
||||
mut total := 0
|
||||
for x in a {
|
||||
total += x
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
fn main() {
|
||||
b := [5, 6, 7]
|
||||
println(sum(1, 2, ...b))
|
||||
}
|
Loading…
Reference in New Issue