mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix fn mut args of array (#10493)
This commit is contained in:
parent
751f2950ea
commit
a98d644637
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user