v/parser: error if parameter name starts with a capital

Before the error was confusing for `fn g<T>(T v)`:
error: cannot use `int literal` as `v` in argument 1 to `g`
pull/13827/head
Nick Treleaven 2022-03-25 15:55:55 +00:00 committed by Delyan Angelov
parent 7f28d91190
commit 532e5c45bf
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 20 additions and 0 deletions

View File

@ -833,6 +833,9 @@ fn (mut p Parser) fn_args() ([]ast.Param, bool, bool) {
}
mut arg_pos := [p.tok.pos()]
mut arg_names := [p.check_name()]
if arg_names[0][0].is_capital() {
p.error_with_pos('parameter name must not begin with upper case letter (`${arg_names[0]}`)', p.prev_tok.pos())
}
mut type_pos := [p.tok.pos()]
// `a, b, c int`
for p.tok.kind == .comma {

View File

@ -0,0 +1,7 @@
vlib/v/parser/tests/fn_param_name_cap.vv:6:9: error: parameter name must not begin with upper case letter (`T`)
4 | fn f(Type)
5 |
6 | fn g<T>(T v) {
| ^
7 |
8 | }

View File

@ -0,0 +1,10 @@
type Type = int
// OK
fn f(Type)
fn g<T>(T v) {
}
g(5)