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
parent
7f28d91190
commit
532e5c45bf
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 | }
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
type Type = int
|
||||
|
||||
// OK
|
||||
fn f(Type)
|
||||
|
||||
fn g<T>(T v) {
|
||||
|
||||
}
|
||||
|
||||
g(5)
|
||||
Loading…
Reference in New Issue