From fdabd27be80907c251e3489407a3672906b4f579 Mon Sep 17 00:00:00 2001 From: yuyi Date: Tue, 19 Sep 2023 19:02:26 +0800 Subject: [PATCH] cgen: fix channel of interface (fix #19382) (#19383) --- vlib/v/gen/c/fn.v | 3 +++ vlib/v/tests/chan_interface_test.v | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 vlib/v/tests/chan_interface_test.v 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 +}