cgen: fix fn mut arg of array (#11104)

pull/11112/head
yuyi 2021-08-09 06:49:30 +08:00 committed by GitHub
parent 52a3360a47
commit eed8c4671f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -1296,7 +1296,8 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
} else if arg_is_ptr && !expr_is_ptr {
if arg.is_mut {
if exp_sym.kind == .array {
if arg.expr is ast.Ident && (arg.expr as ast.Ident).kind == .variable {
if (arg.expr is ast.Ident && (arg.expr as ast.Ident).kind == .variable)
|| arg.expr is ast.SelectorExpr {
g.write('&/*arr*/')
g.expr(arg.expr)
} else {

View File

@ -0,0 +1,24 @@
fn test_fn_mut_arg_of_array() {
mut a := App{}
a.data << 1
a.do_something()
assert a.data.len == 2
}
struct App {
pub mut:
data []int
}
fn (mut a App) do_something() {
assert a.data.len == 1
mut p := Proc{}
p.make_a(mut a.data)
assert a.data.len == 2
}
struct Proc {}
fn (mut p Proc) make_a(mut data []int) {
data << 2
}