autofree: fix optional returns

pull/9617/head
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 { if optional_none || is_regular_option || node.types[0] == ast.error_type_idx {
g.write('return ') g.write('return ')
g.gen_optional_error(g.fn_decl.return_type, node.exprs[0]) g.gen_optional_error(g.fn_decl.return_type, node.exprs[0])
// g.writeln('; /*ret1*/')
g.writeln(';') g.writeln(';')
return return
} }
@ -4778,6 +4779,7 @@ fn (mut g Gen) return_statement(node ast.Return) {
} }
} }
g.writeln(' }, (Option*)(&$opt_tmp), sizeof($styp));') 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;') g.writeln('return $opt_tmp;')
return return
} }

View File

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