From 2335e545eb994e658f558fb95d6fe9af22ddab2a Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 26 Feb 2026 20:40:23 +0300 Subject: [PATCH] cgen: fix autofree compile error '{' expected (fixes #25366) --- vlib/v/gen/c/assign.v | 2 +- .../gen/c/testdata/autofree_mut_array_reassign.out | 0 .../v/gen/c/testdata/autofree_mut_array_reassign.vv | 13 +++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 vlib/v/gen/c/testdata/autofree_mut_array_reassign.out create mode 100644 vlib/v/gen/c/testdata/autofree_mut_array_reassign.vv diff --git a/vlib/v/gen/c/assign.v b/vlib/v/gen/c/assign.v index 52ecec01b..0e3584fb4 100644 --- a/vlib/v/gen/c/assign.v +++ b/vlib/v/gen/c/assign.v @@ -265,7 +265,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) { g.write('${type_to_free} ${sref_name} = (') // TODO: we are copying the entire string here, optimize // we can't just do `.str` since we need the extra data from the string struct // doing `&string` is also not an option since the stack memory with the data will be overwritten - if left0.is_auto_deref_var() { + if left0.is_auto_deref_var() && !first_left_type.has_flag(.shared_f) { g.write('*') } g.expr(left0) // node.left[0]) diff --git a/vlib/v/gen/c/testdata/autofree_mut_array_reassign.out b/vlib/v/gen/c/testdata/autofree_mut_array_reassign.out new file mode 100644 index 000000000..e69de29bb diff --git a/vlib/v/gen/c/testdata/autofree_mut_array_reassign.vv b/vlib/v/gen/c/testdata/autofree_mut_array_reassign.vv new file mode 100644 index 000000000..0f34bf7c5 --- /dev/null +++ b/vlib/v/gen/c/testdata/autofree_mut_array_reassign.vv @@ -0,0 +1,13 @@ +// vtest vflags: -autofree +struct MyS { + a int +} + +fn need_free(mut x []MyS) { + x = []MyS{} +} + +fn main() { + mut xx := []MyS{} + need_free(mut xx) +} -- 2.39.5