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

parser: error if parameter name starts with a capital (#13827)

This commit is contained in:
Nick Treleaven 2022-03-26 17:56:34 +00:00 committed by GitHub
parent 8c396356bb
commit fcb57312b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View File

@ -832,7 +832,12 @@ fn (mut p Parser) fn_args() ([]ast.Param, bool, bool) {
p.next()
}
mut arg_pos := [p.tok.pos()]
mut arg_names := [p.check_name()]
name := p.check_name()
mut arg_names := [name]
if name.len > 0 && name[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)