diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index d29b51f1d3ef1b..7aee2789982f2e 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -2256,6 +2256,9 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as g.write('(voidptr)&/*qq*/') } else { needs_closing = true + if arg_typ_sym.kind in [.sum_type, .interface_] { + atype = arg_typ + } g.write('ADDR(${g.typ(atype)}/*qq*/, ') } } diff --git a/vlib/v/tests/chan_interface_test.v b/vlib/v/tests/chan_interface_test.v new file mode 100644 index 00000000000000..eb7a2f3926efc1 --- /dev/null +++ b/vlib/v/tests/chan_interface_test.v @@ -0,0 +1,17 @@ +interface TestInterface { + a int +} + +struct TestStruct { + a int +} + +fn test_chan_interface() { + c := chan TestInterface{cap: 1} + + c.try_push(TestInterface(TestStruct{ a: 1 })) + + m := <-c + println(m) + assert m.a == 1 +}