diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 133049e95a..e8dcfea538 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -544,6 +544,9 @@ fn (mut p Parser) anon_fn() ast.AnonFn { // TODO generics args, _, is_variadic := p.fn_args() for arg in args { + if arg.name.len == 0 { + p.error_with_pos('use `_` to name an unused parameter', arg.pos) + } p.scope.register(ast.Var{ name: arg.name typ: arg.typ diff --git a/vlib/v/parser/tests/anon_unused_param.out b/vlib/v/parser/tests/anon_unused_param.out new file mode 100644 index 0000000000..a12769b300 --- /dev/null +++ b/vlib/v/parser/tests/anon_unused_param.out @@ -0,0 +1,4 @@ +vlib/v/parser/tests/anon_unused_param.vv:1:9: error: use `_` to name an unused parameter + 1 | _ = fn (int){} + | ~~~ + 2 | diff --git a/vlib/v/parser/tests/anon_unused_param.vv b/vlib/v/parser/tests/anon_unused_param.vv new file mode 100644 index 0000000000..c285cea3c9 --- /dev/null +++ b/vlib/v/parser/tests/anon_unused_param.vv @@ -0,0 +1,2 @@ +_ = fn (int){} +