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

checker: fix unrecognised empty argument names in anon fn's (#13176)

This commit is contained in:
trueFireblade 2022-01-15 07:23:30 +01:00 committed by GitHub
parent f19197f9b0
commit 9fd65b5b18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View File

@ -323,6 +323,11 @@ fn (mut c Checker) anon_fn(mut node ast.AnonFn) ast.Type {
c.table.cur_fn = keep_fn
c.inside_anon_fn = keep_inside_anon
}
for param in node.decl.params {
if param.name.len == 0 {
c.error('use `_` to name an unused parameter', param.pos)
}
}
c.table.cur_fn = unsafe { &node.decl }
c.inside_anon_fn = true
for mut var in node.inherited_vars {

View File

@ -1,3 +1,10 @@
vlib/v/checker/tests/anon_fn_arg_type_err.vv:6:14: error: use `_` to name an unused parameter
4 | mut i := 1
5 |
6 | func := fn (i) int {
| ^
7 | return i
8 | }
vlib/v/checker/tests/anon_fn_arg_type_err.vv:7:10: error: undefined ident: `i`
5 |
6 | func := fn (i) int {
@ -5,13 +12,6 @@ vlib/v/checker/tests/anon_fn_arg_type_err.vv:7:10: error: undefined ident: `i`
| ^
8 | }
9 |
vlib/v/checker/tests/anon_fn_arg_type_err.vv:6:14: error: unknown type `i`
4 | mut i := 1
5 |
6 | func := fn (i) int {
| ^
7 | return i
8 | }
vlib/v/checker/tests/anon_fn_arg_type_err.vv:10:15: error: cannot use `int` as `i` in argument 1 to `func`
8 | }
9 |