From 9fd65b5b185b0df2ad92567030023e0ba67723cc Mon Sep 17 00:00:00 2001 From: trueFireblade <49287879+trueFireblade@users.noreply.github.com> Date: Sat, 15 Jan 2022 07:23:30 +0100 Subject: [PATCH] checker: fix unrecognised empty argument names in anon fn's (#13176) --- vlib/v/checker/fn.v | 5 +++++ vlib/v/checker/tests/anon_fn_arg_type_err.out | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 1c002bd3a2..905f1567f3 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -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 { diff --git a/vlib/v/checker/tests/anon_fn_arg_type_err.out b/vlib/v/checker/tests/anon_fn_arg_type_err.out index 369a7daa93..a45921cad9 100644 --- a/vlib/v/checker/tests/anon_fn_arg_type_err.out +++ b/vlib/v/checker/tests/anon_fn_arg_type_err.out @@ -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 |