diff --git a/vlib/v/checker/tests/anon_fn_arg_type_err.out b/vlib/v/checker/tests/anon_fn_arg_type_err.out new file mode 100644 index 0000000000..369a7daa93 --- /dev/null +++ b/vlib/v/checker/tests/anon_fn_arg_type_err.out @@ -0,0 +1,20 @@ +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: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 | + 10 | println(func(i) == 1) + | ^ + 11 | } diff --git a/vlib/v/checker/tests/anon_fn_arg_type_err.vv b/vlib/v/checker/tests/anon_fn_arg_type_err.vv new file mode 100644 index 0000000000..e1608b329c --- /dev/null +++ b/vlib/v/checker/tests/anon_fn_arg_type_err.vv @@ -0,0 +1,11 @@ +module main + +fn main() { + mut i := 1 + + func := fn (i) int { + return i + } + + println(func(i) == 1) +} diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 56eb9bb975..e3c839c23d 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -642,7 +642,7 @@ 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 { + if arg.name.len == 0 && p.table.sym(arg.typ).kind != .placeholder { p.error_with_pos('use `_` to name an unused parameter', arg.pos) } is_stack_obj := !arg.typ.has_flag(.shared_f) && (arg.is_mut || arg.typ.is_ptr()) @@ -811,6 +811,7 @@ fn (mut p Parser) fn_args() ([]ast.Param, bool, bool) { name: '' is_mut: is_mut typ: arg_type + type_pos: pos } arg_no++ if arg_no > 1024 {