Skip to content

Commit dbaa918

Browse files
committed
autofree: fix optional returns
1 parent cbcc0d3 commit dbaa918

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

vlib/v/gen/c/cgen.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4664,6 +4664,7 @@ fn (mut g Gen) return_statement(node ast.Return) {
46644664
if optional_none || is_regular_option || node.types[0] == ast.error_type_idx {
46654665
g.write('return ')
46664666
g.gen_optional_error(g.fn_decl.return_type, node.exprs[0])
4667+
// g.writeln('; /*ret1*/')
46674668
g.writeln(';')
46684669
return
46694670
}
@@ -4778,6 +4779,7 @@ fn (mut g Gen) return_statement(node ast.Return) {
47784779
}
47794780
}
47804781
g.writeln(' }, (Option*)(&$opt_tmp), sizeof($styp));')
4782+
g.autofree_scope_vars(node.pos.pos - 1, node.pos.line_nr, true)
47814783
g.writeln('return $opt_tmp;')
47824784
return
47834785
}

vlib/v/tests/valgrind/1.strings_and_arrays.v

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ fn parse_header0(s string) ?string {
353353
return error('missing colon in header')
354354
}
355355
words := s.split_nth(':', 2)
356+
// x := words[0]
357+
// return x
356358
return words[0]
357359
}
358360

@@ -386,7 +388,7 @@ fn main() {
386388
s2 := return_sb_str()
387389
// free_map()
388390
// loop_map()
389-
// advanced_optionals()
391+
advanced_optionals()
390392
free_array_except_returned_element()
391393
println('end')
392394
}

0 commit comments

Comments
 (0)