1
0
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:
yuyi 2023-07-27 17:36:44 +08:00 committed by GitHub
parent d25e213aa8
commit fde0d9fa91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -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

View File

@ -0,0 +1,11 @@
fn f() !string {
return 'abc'
}
fn g(s string) {
println(s)
}
fn main() {
g(f()!)
}