Skip to content

Commit

Permalink
checker: fix blank_ident as param of lambda exprs (fix #19853) (#19856)
Browse files Browse the repository at this point in the history
  • Loading branch information
shove70 committed Nov 13, 2023
1 parent c9df064 commit e0207b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions vlib/v/checker/lambda_expr.v
Expand Up @@ -129,8 +129,10 @@ pub fn (mut c Checker) lambda_expr_fix_type_of_param(mut node ast.LambdaExpr, mu
v.expr = ast.empty_expr
}
}
c.ident(mut pident)
pident.obj.typ = ptype
if pident.kind != .blank_ident {
c.ident(mut pident)
pident.obj.typ = ptype
}
}

pub fn (mut c Checker) support_lambda_expr_in_sort(param_type ast.Type, return_type ast.Type, mut expr ast.LambdaExpr) {
Expand Down
9 changes: 9 additions & 0 deletions vlib/v/tests/lambda_expr_test.v
Expand Up @@ -45,3 +45,12 @@ fn test_fn_with_callback_called_with_lambda_expression() {
}) == 'a: 10, b: 20'
assert doit(100, 200, |a, b| 'a: ${a}, b: ${b}') == 'a: 100, b: 200'
}

// for test params has blank_ident
fn f4(g fn (int) string) {
assert g(0) == 'hello'
}

fn test_params_has_blank_ident() {
f4(|_| 'hello')
}

0 comments on commit e0207b6

Please sign in to comment.