1
0
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:
Nick Treleaven 2021-03-12 12:17:37 +00:00 committed by GitHub
parent 504b87bcfd
commit 3be78d6777
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 0 deletions

View File

@ -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

View 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 |

View File

@ -0,0 +1,2 @@
_ = fn (int){}