memory: handle string assignments

pull/4103/head
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.expr(val)
g.write(')') 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 { else if !is_fixed_array_init {
g.write(' = ') g.write(' = ')
if !is_decl { if !is_decl {

View File

@ -10,7 +10,7 @@ fn foo() {
nums_copy := nums // array assignments call .clone() nums_copy := nums // array assignments call .clone()
println(nums) println(nums)
println(nums_copy) println(nums_copy)
nums.free() // nums.free() // this should result in a double free and a CI error
} }
fn main() { fn main() {