Skip to content

Commit

Permalink
cgen: fix channel of interface (fix #19382) (#19383)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 authored Sep 19, 2023
1 parent f9334c8 commit fdabd27
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vlib/v/gen/c/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -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*/, ')
}
}
Expand Down
17 changes: 17 additions & 0 deletions vlib/v/tests/chan_interface_test.v
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit fdabd27

Please sign in to comment.