From 056f1b7c06638f8658bd03aa01e38834c9dc3b79 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 5 Nov 2022 19:58:22 +0200 Subject: [PATCH] parser: improve error message for `fn (a Foo>) baz(){}` --- vlib/v/parser/parse_type.v | 2 +- vlib/v/parser/tests/generic_struct_parameter_err.out | 2 +- .../tests/generic_struct_receiver_nested_generic_err.out | 5 +++++ .../tests/generic_struct_receiver_nested_generic_err.vv | 5 +++++ 4 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 vlib/v/parser/tests/generic_struct_receiver_nested_generic_err.out create mode 100644 vlib/v/parser/tests/generic_struct_receiver_nested_generic_err.vv diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index c62566f642..5c28506207 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -682,7 +682,7 @@ pub fn (mut p Parser) parse_generic_inst_type(name string) ast.Type { p.error_with_pos('cannot use multi return as generic concrete type', type_pos) } if !is_instance && gts.name.len > 1 { - p.error_with_pos('generic struct parameter name needs to be exactly one char', + p.error_with_pos('the parameter type name of a generic struct, must be a single capital letter placeholder name, like T or X, or a non-generic type name like int, string, etc.', type_pos) } bs_name += gts.name diff --git a/vlib/v/parser/tests/generic_struct_parameter_err.out b/vlib/v/parser/tests/generic_struct_parameter_err.out index dcb4658b3d..7cd5d0c4a1 100644 --- a/vlib/v/parser/tests/generic_struct_parameter_err.out +++ b/vlib/v/parser/tests/generic_struct_parameter_err.out @@ -1,4 +1,4 @@ -vlib/v/parser/tests/generic_struct_parameter_err.vv:10:17: error: generic struct parameter name needs to be exactly one char +vlib/v/parser/tests/generic_struct_parameter_err.vv:10:17: error: the parameter type name of a generic struct, must be a single capital letter placeholder name, like T or X, or a non-generic type name like int, string, etc. 8 | struct MyContainer { 9 | mut: 10 | lst LinkedList> diff --git a/vlib/v/parser/tests/generic_struct_receiver_nested_generic_err.out b/vlib/v/parser/tests/generic_struct_receiver_nested_generic_err.out new file mode 100644 index 0000000000..e5de23ce49 --- /dev/null +++ b/vlib/v/parser/tests/generic_struct_receiver_nested_generic_err.out @@ -0,0 +1,5 @@ +vlib/v/parser/tests/generic_struct_receiver_nested_generic_err.vv:5:11: error: the parameter type name of a generic struct, must be a single capital letter placeholder name, like T or X, or a non-generic type name like int, string, etc. + 3 | } + 4 | + 5 | fn (a Foo>) baz() {} + | ~~~~~~ diff --git a/vlib/v/parser/tests/generic_struct_receiver_nested_generic_err.vv b/vlib/v/parser/tests/generic_struct_receiver_nested_generic_err.vv new file mode 100644 index 0000000000..e37b17a919 --- /dev/null +++ b/vlib/v/parser/tests/generic_struct_receiver_nested_generic_err.vv @@ -0,0 +1,5 @@ +struct Foo { + bar T +} + +fn (a Foo>) baz() {}