diff --git a/vlib/v/checker/lambda_expr.v b/vlib/v/checker/lambda_expr.v index 20c77fb520e736..246b5d7cb5e609 100644 --- a/vlib/v/checker/lambda_expr.v +++ b/vlib/v/checker/lambda_expr.v @@ -7,11 +7,6 @@ pub fn (mut c Checker) lambda_expr(mut node ast.LambdaExpr, exp_typ ast.Type) as if node.is_checked { return node.typ } - if !c.inside_fn_arg { - c.error('lambda expressions are allowed only inside function or method callsites', - node.pos) - return ast.void_type - } if exp_typ == 0 { c.error('lambda expressions are allowed only in places expecting function callbacks', node.pos) diff --git a/vlib/v/parser/expr.v b/vlib/v/parser/expr.v index 4c93f8773edf76..ba69499a54dbcb 100644 --- a/vlib/v/parser/expr.v +++ b/vlib/v/parser/expr.v @@ -837,10 +837,6 @@ fn (mut p Parser) process_custom_orm_operators() { } fn (mut p Parser) lambda_expr() ?ast.LambdaExpr { - if !p.inside_call_args { - return none - } - // a) `f(||expr)` for a callback lambda expression with 0 arguments // b) `f(|a_1,...,a_n| expr_with_a_1_etc_till_a_n)` for a callback with several arguments if !(p.tok.kind == .logical_or diff --git a/vlib/v/tests/lambda_as_struct_field_value_test.v b/vlib/v/tests/lambda_as_struct_field_value_test.v new file mode 100644 index 00000000000000..712e438c94c08f --- /dev/null +++ b/vlib/v/tests/lambda_as_struct_field_value_test.v @@ -0,0 +1,10 @@ +struct Foo { + sum fn (int, int) int +} + +fn test_lambda_as_struct_field_value() { + foo := Foo{ + sum: |x, y| x + y + } + assert foo.sum(6, 6) == 12 +}