mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
memory: handle string assignments
This commit is contained in:
parent
043ea80fa9
commit
8d8907b61e
@ -512,6 +512,12 @@ fn (g mut Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
|
||||
g.expr(val)
|
||||
g.write(')')
|
||||
}
|
||||
else if g.autofree && right_sym.kind == .string && is_ident {
|
||||
// `str1 = str2` => `str1 = str2.clone()`
|
||||
g.write(' = string_clone(')
|
||||
g.expr(val)
|
||||
g.write(')')
|
||||
}
|
||||
else if !is_fixed_array_init {
|
||||
g.write(' = ')
|
||||
if !is_decl {
|
||||
|
@ -10,7 +10,7 @@ fn foo() {
|
||||
nums_copy := nums // array assignments call .clone()
|
||||
println(nums)
|
||||
println(nums_copy)
|
||||
nums.free()
|
||||
// nums.free() // this should result in a double free and a CI error
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
Loading…
Reference in New Issue
Block a user