cgen: fix ref and deref when an interface is used as a function parameter (fix #19947) (#19966)

This commit is contained in:
shove 2023-11-22 21:34:43 +08:00 committed by GitHub
parent 980912dc96
commit d577e54152
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -2318,6 +2318,10 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
g.write(')')
return
}
} else if arg_sym.kind == .interface_ && exp_sym.kind == .interface_ {
if exp_is_ptr && !arg_is_ptr {
g.write('&')
}
}
}
} else if arg_typ.has_flag(.shared_f) && !expected_type.has_flag(.shared_f) {

View File

@ -0,0 +1,12 @@
interface Foo {}
fn has_interface_args(mut a Foo, b &Foo, c Foo) {
assert a == &Foo(1)
assert b == &Foo(1)
assert c == Foo(1)
}
fn test_fn_call_interface_args() {
mut arg := Foo(1)
has_interface_args(mut arg, arg, arg)
}