mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix compiling 'f(g()!)' with -autofree (#18979)
This commit is contained in:
parent
d25e213aa8
commit
fde0d9fa91
@ -507,8 +507,11 @@ fn (mut c Checker) call_expr(mut node ast.CallExpr) ast.Type {
|
|||||||
c.inside_fn_arg = old_inside_fn_arg
|
c.inside_fn_arg = old_inside_fn_arg
|
||||||
// autofree: mark args that have to be freed (after saving them in tmp exprs)
|
// 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
|
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)
|
&& !c.inside_const && !node.args[0].typ.has_flag(.option)
|
||||||
if free_tmp_arg_vars && !c.inside_const {
|
&& !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 {
|
for i, arg in node.args {
|
||||||
if arg.typ != ast.string_type {
|
if arg.typ != ast.string_type {
|
||||||
continue
|
continue
|
||||||
|
11
vlib/v/slow_tests/valgrind/fn_call_result_arg.v
Normal file
11
vlib/v/slow_tests/valgrind/fn_call_result_arg.v
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fn f() !string {
|
||||||
|
return 'abc'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn g(s string) {
|
||||||
|
println(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
g(f()!)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user