1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: improve error message for fn (a Foo<Foo<T>>) baz(){}

This commit is contained in:
Delyan Angelov 2022-11-05 19:58:22 +02:00
parent 27d8f2371d
commit 056f1b7c06
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
4 changed files with 12 additions and 2 deletions

View File

@ -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) p.error_with_pos('cannot use multi return as generic concrete type', type_pos)
} }
if !is_instance && gts.name.len > 1 { 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) type_pos)
} }
bs_name += gts.name bs_name += gts.name

View File

@ -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<T> { 8 | struct MyContainer<T> {
9 | mut: 9 | mut:
10 | lst LinkedList<MyNode<T>> 10 | lst LinkedList<MyNode<T>>

View File

@ -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<Foo<T>>) baz() {}
| ~~~~~~

View File

@ -0,0 +1,5 @@
struct Foo<T> {
bar T
}
fn (a Foo<Foo<T>>) baz() {}