cgen: fix fn mut argument of interface type (#13616)

pull/13618/head weekly.2022.09
yuyi 2022-02-28 19:31:04 +08:00 committed by GitHub
parent 013589e9fe
commit 9a2df0df0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View File

@ -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 {

View 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'
}