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

autofree: fix optional returns

This commit is contained in:
Alexander Medvednikov 2021-04-06 17:14:07 +03:00
parent cbcc0d34b5
commit dbaa91810f
2 changed files with 5 additions and 1 deletions

View File

@ -4664,6 +4664,7 @@ fn (mut g Gen) return_statement(node ast.Return) {
if optional_none || is_regular_option || node.types[0] == ast.error_type_idx {
g.write('return ')
g.gen_optional_error(g.fn_decl.return_type, node.exprs[0])
// g.writeln('; /*ret1*/')
g.writeln(';')
return
}
@ -4778,6 +4779,7 @@ fn (mut g Gen) return_statement(node ast.Return) {
}
}
g.writeln(' }, (Option*)(&$opt_tmp), sizeof($styp));')
g.autofree_scope_vars(node.pos.pos - 1, node.pos.line_nr, true)
g.writeln('return $opt_tmp;')
return
}

View File

@ -353,6 +353,8 @@ fn parse_header0(s string) ?string {
return error('missing colon in header')
}
words := s.split_nth(':', 2)
// x := words[0]
// return x
return words[0]
}
@ -386,7 +388,7 @@ fn main() {
s2 := return_sb_str()
// free_map()
// loop_map()
// advanced_optionals()
advanced_optionals()
free_array_except_returned_element()
println('end')
}