1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix fn voidptr param calling with nonpointer rvalue (fix #18424) (#18462)

This commit is contained in:
yuyi 2023-06-16 14:48:12 +08:00 committed by GitHub
parent 1623cc3a51
commit 073a651f7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -2204,7 +2204,7 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
if atype.has_flag(.generic) {
atype = g.unwrap_generic(atype)
}
if atype.has_flag(.generic) {
if atype.has_flag(.generic) || arg.expr is ast.StructInit {
g.write('(voidptr)&/*qq*/')
} else {
needs_closing = true

View File

@ -0,0 +1,23 @@
import eventbus
struct MyMessage {
msg string
}
fn test_fn_call_with_nonpointer_rvalue() {
eb := eventbus.new()
mut subscriber := eb.subscriber
subscriber.subscribe('my_publish', subscriber_method)
do_something(eb)
assert true
}
fn subscriber_method(receiver voidptr, ev &MyMessage, sender voidptr) {
println(ev)
}
fn do_something(eb &eventbus.EventBus) {
eb.publish('my_publish', eb, MyMessage{ msg: 'this is my message' })
}