cgen: don't generate a default expr if a function ends with `return` (#6766)
parent
6d8a7ced24
commit
1d706674f2
|
@ -158,8 +158,8 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl, skip bool) {
|
|||
// TODO: remove this, when g.write_autofree_stmts_when_needed works properly
|
||||
g.autofree_scope_vars(it.body_pos.pos)
|
||||
}
|
||||
if it.return_type != table.void_type {
|
||||
mut default_expr := g.type_default(it.return_type)
|
||||
if it.return_type != table.void_type && it.stmts.len > 0 && it.stmts.last() !is ast.Return {
|
||||
default_expr := g.type_default(it.return_type)
|
||||
// TODO: perf?
|
||||
if default_expr == '{0}' {
|
||||
g.writeln('\treturn ($type_name)$default_expr;')
|
||||
|
|
Loading…
Reference in New Issue