mirror of
https://github.com/vlang/v.git
synced 2025-09-16 19:06:24 -04:00
checker: ignore last semicolon on or-expr (#21361)
This commit is contained in:
parent
f33b712e84
commit
f2f7fc3295
@ -1308,7 +1308,8 @@ fn (mut c Checker) check_or_expr(node ast.OrExpr, ret_type ast.Type, expr_return
|
||||
// allow `f() or {}`
|
||||
return
|
||||
}
|
||||
mut last_stmt := node.stmts.last()
|
||||
mut valid_stmts := node.stmts.filter(it !is ast.SemicolonStmt)
|
||||
mut last_stmt := if valid_stmts.len > 0 { valid_stmts.last() } else { node.stmts.last() }
|
||||
c.check_or_last_stmt(mut last_stmt, ret_type, expr_return_type.clear_option_and_result())
|
||||
}
|
||||
|
||||
|
11
vlib/v/tests/last_stmt_semicolon_or_expr_test.v
Normal file
11
vlib/v/tests/last_stmt_semicolon_or_expr_test.v
Normal file
@ -0,0 +1,11 @@
|
||||
fn foo() !int {
|
||||
return 0
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
mut x := 1
|
||||
// vfmt off
|
||||
x = foo() or { panic("failed"); }
|
||||
// vfmt on
|
||||
println('x=${x}')
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user