checker: fix panic when calling generic function with too few args (#8416)
parent
8398e2f448
commit
2a32dac40d
|
@ -421,14 +421,11 @@ pub fn (mut c Checker) infer_fn_types(f table.Fn, mut call_expr ast.CallExpr) {
|
||||||
}
|
}
|
||||||
mut typ := table.void_type
|
mut typ := table.void_type
|
||||||
for i, param in f.params {
|
for i, param in f.params {
|
||||||
if call_expr.args.len == 0 {
|
arg_i := if i != 0 && call_expr.is_method { i - 1 } else { i }
|
||||||
|
if call_expr.args.len <= arg_i {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
arg := if i != 0 && call_expr.is_method {
|
arg := call_expr.args[arg_i]
|
||||||
call_expr.args[i - 1]
|
|
||||||
} else {
|
|
||||||
call_expr.args[i]
|
|
||||||
}
|
|
||||||
param_type_sym := c.table.get_type_symbol(param.typ)
|
param_type_sym := c.table.get_type_symbol(param.typ)
|
||||||
if param.typ.has_flag(.generic) && param_type_sym.name == gt_name {
|
if param.typ.has_flag(.generic) && param_type_sym.name == gt_name {
|
||||||
typ = arg.typ
|
typ = arg.typ
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
vlib/v/checker/tests/function_count_of_args_mismatch_err.vv:8:13: error: expected 1 arguments, but got 3
|
||||||
|
6 |
|
||||||
|
7 | fn main() {
|
||||||
|
8 | test(true, false, 1)
|
||||||
|
| ~~~~~~~~
|
||||||
|
9 | test()
|
||||||
|
10 | test2(true, false, 1)
|
||||||
|
vlib/v/checker/tests/function_count_of_args_mismatch_err.vv:9:2: error: expected 1 arguments, but got 0
|
||||||
|
7 | fn main() {
|
||||||
|
8 | test(true, false, 1)
|
||||||
|
9 | test()
|
||||||
|
| ~~~~~~
|
||||||
|
10 | test2(true, false, 1)
|
||||||
|
11 | test2(true)
|
||||||
|
vlib/v/checker/tests/function_count_of_args_mismatch_err.vv:10:21: error: expected 2 arguments, but got 3
|
||||||
|
8 | test(true, false, 1)
|
||||||
|
9 | test()
|
||||||
|
10 | test2(true, false, 1)
|
||||||
|
| ^
|
||||||
|
11 | test2(true)
|
||||||
|
12 | }
|
||||||
|
vlib/v/checker/tests/function_count_of_args_mismatch_err.vv:11:2: error: expected 2 arguments, but got 1
|
||||||
|
9 | test()
|
||||||
|
10 | test2(true, false, 1)
|
||||||
|
11 | test2(true)
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
12 | }
|
|
@ -0,0 +1,12 @@
|
||||||
|
fn test(b bool) {
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test2<T>(b bool, v T) {
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
test(true, false, 1)
|
||||||
|
test()
|
||||||
|
test2(true, false, 1)
|
||||||
|
test2(true)
|
||||||
|
}
|
|
@ -1,6 +0,0 @@
|
||||||
vlib/v/checker/tests/function_too_many_args_err.vv:5:16: error: expected 1 arguments, but got 3
|
|
||||||
3 |
|
|
||||||
4 | fn main() {
|
|
||||||
5 | test(true, false, 1)
|
|
||||||
| ~~~~~~~~
|
|
||||||
6 | }
|
|
|
@ -1,6 +0,0 @@
|
||||||
fn test(b bool) {
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
test(true, false, 1)
|
|
||||||
}
|
|
Loading…
Reference in New Issue