Skip to content

Commit

Permalink
cgen: fix ref and deref when an interface is used as a function param…
Browse files Browse the repository at this point in the history
…eter (fix #19947) (#19966)
  • Loading branch information
shove70 committed Nov 22, 2023
1 parent 980912d commit d577e54
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vlib/v/gen/c/fn.v
Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions vlib/v/tests/fn_call_interface_args_test.v
@@ -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)
}

0 comments on commit d577e54

Please sign in to comment.