cgen: fix bug with duplicate defer generation (#8503)
parent
b40252bd97
commit
4b99d6af95
|
@ -332,6 +332,7 @@ pub:
|
|||
pub mut:
|
||||
stmts []Stmt
|
||||
return_type table.Type
|
||||
has_return bool
|
||||
comments []Comment // comments *after* the header, but *before* `{`; used for InterfaceDecl
|
||||
next_comments []Comment // coments that are one line after the decl; used for InterfaceDecl
|
||||
source_file &File = 0
|
||||
|
|
|
@ -5676,9 +5676,9 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
|
|||
if c.fn_mut_arg_names.len > 0 {
|
||||
c.fn_mut_arg_names.clear()
|
||||
}
|
||||
returns := c.returns || has_top_return(node.stmts)
|
||||
if node.language == .v && !node.no_body && node.return_type != table.void_type && !returns
|
||||
&& node.name !in ['panic', 'exit'] {
|
||||
node.has_return = c.returns || has_top_return(node.stmts)
|
||||
if node.language == .v && !node.no_body && node.return_type != table.void_type
|
||||
&& !node.has_return&& node.name !in ['panic', 'exit'] {
|
||||
if c.inside_anon_fn {
|
||||
c.error('missing return at the end of an anonymous function', node.pos)
|
||||
} else {
|
||||
|
|
|
@ -192,7 +192,7 @@ fn (mut g Gen) gen_fn_decl(node ast.FnDecl, skip bool) {
|
|||
g.fn_mut_arg_names.clear()
|
||||
}
|
||||
|
||||
if node.return_type == table.void_type {
|
||||
if !node.has_return {
|
||||
g.write_defer_stmts_when_needed()
|
||||
}
|
||||
if node.is_anon {
|
||||
|
|
Loading…
Reference in New Issue