1
0
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:
Alexander Medvednikov 2020-03-22 13:40:53 +01:00
parent 043ea80fa9
commit 8d8907b61e
2 changed files with 7 additions and 1 deletions

View File

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

View File

@ -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() {