From 8586f18383544882a05a863f390aa2f5aeac8a46 Mon Sep 17 00:00:00 2001 From: shove Date: Sat, 29 Jul 2023 20:38:39 +0800 Subject: [PATCH] checker: fix compiler crashes when passing an extra decompose parameter to a function(fix: 18995) (#18996) --- vlib/v/checker/fn.v | 2 +- .../checker/tests/fn_array_decompose_arg_mismatch_err_c.out | 6 ++++++ .../checker/tests/fn_array_decompose_arg_mismatch_err_c.vv | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 vlib/v/checker/tests/fn_array_decompose_arg_mismatch_err_c.out create mode 100644 vlib/v/checker/tests/fn_array_decompose_arg_mismatch_err_c.vv diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 874559339e..8acbdf5d6c 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -2304,7 +2304,7 @@ fn (mut c Checker) check_expected_arg_count(mut node ast.CallExpr, f &ast.Fn) ! has_decompose := node.args.filter(it.expr is ast.ArrayDecompose).len > 0 if has_decompose { // if call(...args) is present - min_required_params = nr_args + min_required_params = nr_args - 1 } } if min_required_params < 0 { diff --git a/vlib/v/checker/tests/fn_array_decompose_arg_mismatch_err_c.out b/vlib/v/checker/tests/fn_array_decompose_arg_mismatch_err_c.out new file mode 100644 index 0000000000..80a9d20011 --- /dev/null +++ b/vlib/v/checker/tests/fn_array_decompose_arg_mismatch_err_c.out @@ -0,0 +1,6 @@ +vlib/v/checker/tests/fn_array_decompose_arg_mismatch_err_c.vv:2:6: error: expected 0 arguments, but got 1 + 1 | fn main() { + 2 | foo(...args) + | ~~~~~~~ + 3 | } + 4 | diff --git a/vlib/v/checker/tests/fn_array_decompose_arg_mismatch_err_c.vv b/vlib/v/checker/tests/fn_array_decompose_arg_mismatch_err_c.vv new file mode 100644 index 0000000000..4e77356522 --- /dev/null +++ b/vlib/v/checker/tests/fn_array_decompose_arg_mismatch_err_c.vv @@ -0,0 +1,6 @@ +fn main() { + foo(...args) +} + +fn foo() { +}