From daf5d32327d17548ad7e734770113da82924a790 Mon Sep 17 00:00:00 2001 From: JalonSolov Date: Tue, 19 Apr 2022 11:34:23 -0400 Subject: [PATCH] checker: fix error message when number of generic parameters is incorrect (#14090) --- vlib/v/checker/fn.v | 12 ++++-------- .../tests/generics_fn_arguments_count_err.out | 8 ++++---- .../v/checker/tests/generics_too_many_parameters.out | 4 ++-- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 2f67f7b43c..35da5bb63a 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -708,8 +708,8 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) } if node.concrete_types.len > 0 && func.generic_names.len > 0 && node.concrete_types.len != func.generic_names.len { - desc := if node.concrete_types.len > func.generic_names.len { 'many' } else { 'little' } - c.error('too $desc generic parameters got $node.concrete_types.len, expected $func.generic_names.len', + plural := if func.generic_names.len == 1 { '' } else { 's' } + c.error('expected $func.generic_names.len generic parameter$plural, got $node.concrete_types.len', node.concrete_list_pos) } for concrete_type in node.concrete_types { @@ -1231,12 +1231,8 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { } if node.concrete_types.len > 0 && method.generic_names.len > 0 && node.concrete_types.len != method.generic_names.len { - desc := if node.concrete_types.len > method.generic_names.len { - 'many' - } else { - 'little' - } - c.error('too $desc generic parameters got $node.concrete_types.len, expected $method.generic_names.len', + plural := if method.generic_names.len == 1 { '' } else { 's' } + c.error('expected $method.generic_names.len generic parameter$plural, got $node.concrete_types.len', node.concrete_list_pos) } for concrete_type in node.concrete_types { diff --git a/vlib/v/checker/tests/generics_fn_arguments_count_err.out b/vlib/v/checker/tests/generics_fn_arguments_count_err.out index d1c7c6e438..dc9feba117 100644 --- a/vlib/v/checker/tests/generics_fn_arguments_count_err.out +++ b/vlib/v/checker/tests/generics_fn_arguments_count_err.out @@ -1,25 +1,25 @@ -vlib/v/checker/tests/generics_fn_arguments_count_err.vv:12:18: error: too little generic parameters got 1, expected 2 +vlib/v/checker/tests/generics_fn_arguments_count_err.vv:12:18: error: expected 2 generic parameters, got 1 10 | 11 | fn main() { 12 | ret1 := get_name(11, 22) | ~~~~~ 13 | println(ret1) 14 | -vlib/v/checker/tests/generics_fn_arguments_count_err.vv:15:18: error: too many generic parameters got 3, expected 2 +vlib/v/checker/tests/generics_fn_arguments_count_err.vv:15:18: error: expected 2 generic parameters, got 3 13 | println(ret1) 14 | 15 | ret2 := get_name(11, 22, 'hello') | ~~~~~~~~~~~~~~~~~~ 16 | println(ret2) 17 | -vlib/v/checker/tests/generics_fn_arguments_count_err.vv:19:22: error: too little generic parameters got 1, expected 2 +vlib/v/checker/tests/generics_fn_arguments_count_err.vv:19:22: error: expected 2 generic parameters, got 1 17 | 18 | foo := Foo{} 19 | ret3 := foo.get_name(11, 22) | ~~~~~ 20 | println(ret3) 21 | -vlib/v/checker/tests/generics_fn_arguments_count_err.vv:22:22: error: too many generic parameters got 3, expected 2 +vlib/v/checker/tests/generics_fn_arguments_count_err.vv:22:22: error: expected 2 generic parameters, got 3 20 | println(ret3) 21 | 22 | ret4 := foo.get_name(11, 22, 'hello') diff --git a/vlib/v/checker/tests/generics_too_many_parameters.out b/vlib/v/checker/tests/generics_too_many_parameters.out index caea12a161..a54eafdd63 100644 --- a/vlib/v/checker/tests/generics_too_many_parameters.out +++ b/vlib/v/checker/tests/generics_too_many_parameters.out @@ -1,5 +1,5 @@ -vlib/v/checker/tests/generics_too_many_parameters.vv:6:8: error: too many generic parameters got 5, expected 1 - 4 | +vlib/v/checker/tests/generics_too_many_parameters.vv:6:8: error: expected 1 generic parameter, got 5 + 4 | 5 | fn main() { 6 | foo(1) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~