From d5458b58ebd87877de2477b7cdcbfcfabe2747de Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Tue, 12 Aug 2025 15:21:12 +0800 Subject: [PATCH] ast: return cached_name.clone(), as auto_str_methods free it (#25088) --- vlib/v/ast/str.v | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vlib/v/ast/str.v b/vlib/v/ast/str.v index f2f9bb6200..43c98b0954 100644 --- a/vlib/v/ast/str.v +++ b/vlib/v/ast/str.v @@ -400,7 +400,7 @@ __global nested_expr_str_calls = i64(0) const max_nested_expr_str_calls = 300 // string representation of expr -pub fn (x &Expr) str() string { +pub fn (x Expr) str() string { str_calls := stdatomic.add_i64(&nested_expr_str_calls, 1) if str_calls > max_nested_expr_str_calls { $if panic_on_deeply_nested_expr_str_calls ? { @@ -525,13 +525,13 @@ pub fn (x &Expr) str() string { return 'spawn ${x.call_expr}' } Ident { - if x.cached_name != '' { - return x.cached_name + if x.cached_name == '' { + unsafe { + x.cached_name = util.strip_main_name(x.name) + } } - unsafe { - x.cached_name = util.strip_main_name(x.name.clone()) - } - return x.cached_name + // This clone may freed by auto str() + return x.cached_name.clone() } IfExpr { mut parts := []string{}