cgen: fix fn()? return
parent
1ba5996404
commit
c588bdee5a
|
@ -667,7 +667,7 @@ pub fn rmdir_recursive(path string) {
|
|||
pub fn rmdir_all(path string) ? {
|
||||
mut ret_err := ''
|
||||
items := os.ls(path) or {
|
||||
return none
|
||||
return error(err)
|
||||
}
|
||||
for item in items {
|
||||
if os.is_dir(os.join_path(path, item)) {
|
||||
|
|
|
@ -269,6 +269,11 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
|||
body_start_pos := p.peek_tok.position()
|
||||
if p.tok.kind == .lcbr {
|
||||
stmts = p.parse_block_no_scope(true)
|
||||
// Add return if `fn(...) ? {...}` have no return at end
|
||||
if return_type != table.void_type && p.table.get_type_symbol(return_type).kind == .void &&
|
||||
return_type.has_flag(.optional) && (stmts.len == 0 || stmts[stmts.len-1] !is ast.Return) {
|
||||
stmts << ast.Return{ pos: p.tok.position() }
|
||||
}
|
||||
}
|
||||
p.close_scope()
|
||||
if !no_body && are_args_type_only {
|
||||
|
|
Loading…
Reference in New Issue