mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix fn mut argument of interface type (#13616)
This commit is contained in:
parent
013589e9fe
commit
9a2df0df0e
@ -1709,6 +1709,11 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
|
||||
g.write('&/*sum*/')
|
||||
g.expr(arg.expr)
|
||||
return
|
||||
} else if arg_sym.kind == .interface_ && exp_sym.kind == .interface_
|
||||
&& (arg.expr is ast.Ident || arg.expr is ast.SelectorExpr) {
|
||||
g.write('&/*iface*/')
|
||||
g.expr(arg.expr)
|
||||
return
|
||||
}
|
||||
}
|
||||
if !g.is_json_fn {
|
||||
|
27
vlib/v/tests/fn_mut_arg_of_interface_test.v
Normal file
27
vlib/v/tests/fn_mut_arg_of_interface_test.v
Normal file
@ -0,0 +1,27 @@
|
||||
interface TheInterface {
|
||||
mut:
|
||||
an_interface() ?
|
||||
}
|
||||
|
||||
struct Implementation {
|
||||
}
|
||||
|
||||
fn (mut i Implementation) an_interface() ? {
|
||||
return
|
||||
}
|
||||
|
||||
fn maker() ?TheInterface {
|
||||
inner := Implementation{}
|
||||
return inner
|
||||
}
|
||||
|
||||
fn do(mut inter TheInterface) string {
|
||||
return 'ok'
|
||||
}
|
||||
|
||||
fn test_fn_mut_arg_of_interface() ? {
|
||||
mut inner := maker() ?
|
||||
ret := do(mut inner)
|
||||
println(ret)
|
||||
assert ret == 'ok'
|
||||
}
|
Loading…
Reference in New Issue
Block a user