checker: fix lambda expr with result (#20433)

This commit is contained in:
yuyi 2024-01-08 18:41:11 +08:00 committed by GitHub
parent 5cd4933280
commit c7b8da7ffe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -63,7 +63,7 @@ pub fn (mut c Checker) lambda_expr(mut node ast.LambdaExpr, exp_typ ast.Type) as
mut stmts := []ast.Stmt{}
mut has_return := false
if return_type == ast.void_type {
if return_type.clear_flags(.option, .result) == ast.void_type {
stmts << ast.ExprStmt{
pos: node.pos
expr: node.expr

View File

@ -0,0 +1,8 @@
fn test_lambda_expr_with_result() {
take_lambda(|| println('abc'))
assert true
}
fn take_lambda(l fn () !) {
l() or { panic(err) }
}