diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 0bd49e7ed5..da40e36f8f 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -1612,6 +1612,12 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast. c.error('cannot use `${got_typ_str}` as `${expected_typ_str}` in argument ${i + 1} to `${fn_name}`', call_arg.pos) } + if call_arg.expr is ast.ArrayDecompose && arg_typ.idx() != final_param_typ.idx() { + expected_type_str := c.table.type_to_str(param.typ) + got_type_str := c.table.type_to_str(arg_typ) + c.error('cannot use `${got_type_str}` as `${expected_type_str}` in argument ${i + 1} to `${fn_name}`', + call_arg.pos) + } continue } if param.typ.is_ptr() && !param.is_mut && !call_arg.typ.is_any_kind_of_pointer() diff --git a/vlib/v/checker/tests/decompose_interface_err.out b/vlib/v/checker/tests/decompose_interface_err.out new file mode 100644 index 0000000000..c5feaa7e7b --- /dev/null +++ b/vlib/v/checker/tests/decompose_interface_err.out @@ -0,0 +1,20 @@ +vlib/v/checker/tests/decompose_interface_err.vv:3:8: warning: module 'arrays' is imported but never used + 1 | module main + 2 | + 3 | import arrays + | ~~~~~~ + 4 | + 5 | interface Value {} +vlib/v/checker/tests/decompose_interface_err.vv:17:2: warning: unused variable: `region_id` + 15 | 'AF', + 16 | ] + 17 | region_id := 'something' + | ~~~~~~~~~ + 18 | some_function(...country_ids) + 19 | } +vlib/v/checker/tests/decompose_interface_err.vv:18:16: error: cannot use `string` as `Value` in argument 1 to `some_function` + 16 | ] + 17 | region_id := 'something' + 18 | some_function(...country_ids) + | ~~~~~~~~~~~~~~ + 19 | } diff --git a/vlib/v/checker/tests/decompose_interface_err.vv b/vlib/v/checker/tests/decompose_interface_err.vv new file mode 100644 index 0000000000..28a623d2dc --- /dev/null +++ b/vlib/v/checker/tests/decompose_interface_err.vv @@ -0,0 +1,19 @@ +module main + +import arrays + +interface Value {} + +fn some_function(values ...Value) { + println(values) +} + +fn main() { + country_ids := [ + 'AD', + 'AE', + 'AF', + ] + region_id := 'something' + some_function(...country_ids) +}