Skip to content

Commit

Permalink
checker: fix unrecognised empty argument names in anon fn's (#13176)
Browse files Browse the repository at this point in the history
  • Loading branch information
trueFireblade committed Jan 15, 2022
1 parent f19197f commit 9fd65b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions vlib/v/checker/fn.v
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions vlib/v/checker/tests/anon_fn_arg_type_err.out
@@ -1,17 +1,17 @@
vlib/v/checker/tests/anon_fn_arg_type_err.vv:7:10: error: undefined ident: `i`
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 | }
9 |
vlib/v/checker/tests/anon_fn_arg_type_err.vv:6:14: error: unknown type `i`
4 | mut i := 1
vlib/v/checker/tests/anon_fn_arg_type_err.vv:7:10: error: undefined ident: `i`
5 |
6 | func := fn (i) int {
| ^
7 | return i
| ^
8 | }
9 |
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 |
Expand Down

0 comments on commit 9fd65b5

Please sign in to comment.