mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix fn mut arg of array (#11104)
This commit is contained in:
parent
52a3360a47
commit
eed8c4671f
@ -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 {
|
} else if arg_is_ptr && !expr_is_ptr {
|
||||||
if arg.is_mut {
|
if arg.is_mut {
|
||||||
if exp_sym.kind == .array {
|
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.write('&/*arr*/')
|
||||||
g.expr(arg.expr)
|
g.expr(arg.expr)
|
||||||
} else {
|
} else {
|
||||||
|
24
vlib/v/tests/fn_mut_arg_of_array_test.v
Normal file
24
vlib/v/tests/fn_mut_arg_of_array_test.v
Normal 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
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user