cgen: fix fn mut args of array (#10493)

pull/10503/head
yuyi 2021-06-18 07:51:55 +08:00 committed by GitHub
parent 751f2950ea
commit a98d644637
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -760,6 +760,10 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
arg_name := '_arg_expr_${fn_name}_0_$node.pos.pos'
g.write('/*af receiver arg*/' + arg_name)
} else {
if left_sym.kind == .array && node.left.is_auto_deref_var()
&& node.name in ['first', 'last', 'repeat'] {
g.write('*')
}
g.expr(node.left)
if node.from_embed_type != 0 {
embed_name := typ_sym.embed_name()

View File

@ -25,3 +25,21 @@ fn test_fn_mut_args_of_map() {
'one': 1
}
}
struct MyData {
pub mut:
ar []int
}
fn pass_array_mut(mut ar []int) int {
if ar.len > 0 && ar.last() == 99 {
return 99
}
return 0
}
fn test_fn_mut_args_of_array_last() {
mut m := MyData{}
m.ar << 99
assert pass_array_mut(mut m.ar) == 99
}