array: fix memory bug with mutable array args

pull/2068/head
Alexander Medvednikov 2019-09-22 10:32:44 +03:00
parent 45e9a8fd66
commit cec2173381
1 changed files with 5 additions and 1 deletions

View File

@ -461,7 +461,11 @@ fn (p mut Parser) gen_array_push(ph int, typ, expr_type, tmp, tmp_typ string) {
// Don't dereference if it's already a mutable array argument (`fn foo(mut []int)`) // Don't dereference if it's already a mutable array argument (`fn foo(mut []int)`)
push_call := if typ.contains('*'){'_PUSH('} else { '_PUSH(&'} push_call := if typ.contains('*'){'_PUSH('} else { '_PUSH(&'}
p.cgen.set_placeholder(ph, push_call) p.cgen.set_placeholder(ph, push_call)
p.gen('), $tmp, $tmp_typ)') if tmp_typ.ends_with('*') {
p.gen('), $tmp, ${tmp_typ.left(tmp_typ.len - 1)})')
} else {
p.gen('), $tmp, $tmp_typ)')
}
} }
} }