Skip to content

Commit

Permalink
checker: fix compiling 'f(g()!)' with -autofree (#18979)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Jul 27, 2023
1 parent d25e213 commit fde0d9f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions vlib/v/checker/fn.v
Expand Up @@ -507,8 +507,11 @@ fn (mut c Checker) call_expr(mut node ast.CallExpr) ast.Type {
c.inside_fn_arg = old_inside_fn_arg
// autofree: mark args that have to be freed (after saving them in tmp exprs)
free_tmp_arg_vars := c.pref.autofree && !c.is_builtin_mod && node.args.len > 0
&& !node.args[0].typ.has_flag(.option) && !node.args[0].typ.has_flag(.result)
if free_tmp_arg_vars && !c.inside_const {
&& !c.inside_const && !node.args[0].typ.has_flag(.option)
&& !node.args[0].typ.has_flag(.result) && !(node.args[0].expr is ast.CallExpr
&& (node.args[0].expr.return_type.has_flag(.option)
|| node.args[0].expr.return_type.has_flag(.result)))
if free_tmp_arg_vars {
for i, arg in node.args {
if arg.typ != ast.string_type {
continue
Expand Down
11 changes: 11 additions & 0 deletions vlib/v/slow_tests/valgrind/fn_call_result_arg.v
@@ -0,0 +1,11 @@
fn f() !string {
return 'abc'
}

fn g(s string) {
println(s)
}

fn main() {
g(f()!)
}

0 comments on commit fde0d9f

Please sign in to comment.