cgen: fix bug with duplicate defer generation (#8503)

pull/8534/head
zakuro 2021-02-03 18:40:21 +09:00 committed by GitHub
parent b40252bd97
commit 4b99d6af95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 4 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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 {