checker: fix blank_ident as param of lambda exprs (fix #19853) (#19856)

This commit is contained in:
shove 2023-11-13 19:29:36 +08:00 committed by GitHub
parent c9df064407
commit e0207b6830
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -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 v.expr = ast.empty_expr
} }
} }
c.ident(mut pident) if pident.kind != .blank_ident {
pident.obj.typ = ptype 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) { pub fn (mut c Checker) support_lambda_expr_in_sort(param_type ast.Type, return_type ast.Type, mut expr ast.LambdaExpr) {

View File

@ -45,3 +45,12 @@ fn test_fn_with_callback_called_with_lambda_expression() {
}) == 'a: 10, b: 20' }) == 'a: 10, b: 20'
assert doit(100, 200, |a, b| 'a: ${a}, b: ${b}') == 'a: 100, b: 200' 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')
}