ast: return cached_name.clone(), as auto_str_methods free it (#25088)

This commit is contained in:
kbkpbot 2025-08-12 15:21:12 +08:00 committed by GitHub
parent ec29f43a4d
commit d5458b58eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -400,7 +400,7 @@ __global nested_expr_str_calls = i64(0)
const max_nested_expr_str_calls = 300 const max_nested_expr_str_calls = 300
// string representation of expr // 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) str_calls := stdatomic.add_i64(&nested_expr_str_calls, 1)
if str_calls > max_nested_expr_str_calls { if str_calls > max_nested_expr_str_calls {
$if panic_on_deeply_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}' return 'spawn ${x.call_expr}'
} }
Ident { Ident {
if x.cached_name != '' { if x.cached_name == '' {
return x.cached_name
}
unsafe { unsafe {
x.cached_name = util.strip_main_name(x.name.clone()) x.cached_name = util.strip_main_name(x.name)
} }
return x.cached_name }
// This clone may freed by auto str()
return x.cached_name.clone()
} }
IfExpr { IfExpr {
mut parts := []string{} mut parts := []string{}