mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: require anonymous fn to use _
for unused parameters (#9262)
Fixes a C error with gcc.
This commit is contained in:
parent
504b87bcfd
commit
3be78d6777
@ -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
|
||||
|
4
vlib/v/parser/tests/anon_unused_param.out
Normal file
4
vlib/v/parser/tests/anon_unused_param.out
Normal file
@ -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 |
|
2
vlib/v/parser/tests/anon_unused_param.vv
Normal file
2
vlib/v/parser/tests/anon_unused_param.vv
Normal file
@ -0,0 +1,2 @@
|
||||
_ = fn (int){}
|
||||
|
Loading…
Reference in New Issue
Block a user