1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix return_statement generated redundant ; (#9299)

This commit is contained in:
yuyi 2021-03-14 20:58:17 +08:00 committed by GitHub
parent 125be84e3d
commit c0779e8455
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4329,6 +4329,7 @@ fn (mut g Gen) return_statement(node ast.Return) {
sym := g.table.get_type_symbol(g.fn_decl.return_type)
fn_return_is_multi := sym.kind == .multi_return
fn_return_is_optional := g.fn_decl.return_type.has_flag(.optional)
mut has_semicolon := false
if node.exprs.len == 0 {
if fn_return_is_optional {
styp := g.typ(g.fn_decl.return_type)
@ -4502,6 +4503,7 @@ fn (mut g Gen) return_statement(node ast.Return) {
g.returned_var_name = expr.name
}
g.writeln(';')
has_semicolon = true
// autofree before `return`
// set free_parent_scopes to true, since all variables defined in parent
// scopes need to be freed before the return
@ -4510,13 +4512,16 @@ fn (mut g Gen) return_statement(node ast.Return) {
}
if tmp != '' {
g.write('return $tmp')
has_semicolon = false
}
}
} else { // if node.exprs.len == 0 {
println('this should never happen')
g.write('/*F*/return')
}
g.writeln(';')
if !has_semicolon {
g.writeln(';')
}
}
fn (mut g Gen) const_decl(node ast.ConstDecl) {