cgen: fix codegen for passing int from selector to voidptr expect arg (fix #25081) (#25083)

This commit is contained in:
Felipe Pena 2025-08-10 08:01:16 -03:00 committed by GitHub
parent 7b77f2ee5b
commit 36ca628c59
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View file

@ -2707,6 +2707,8 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
} }
if arg.expr.is_as_cast() { if arg.expr.is_as_cast() {
g.inside_smartcast = true g.inside_smartcast = true
} else if arg_typ_sym.is_int() && arg.expr !is ast.CastExpr {
g.write('(voidptr)&')
} else { } else {
g.write('ADDR(${g.styp(atype)}, ') g.write('ADDR(${g.styp(atype)}, ')
needs_closing = true needs_closing = true

View file

@ -0,0 +1,15 @@
struct Foo {
mut:
value int = 123
}
fn test_main() {
shared m := Foo{}
ch := chan int{cap: 1}
ch.try_push(rlock m {
m.value
})
mut tmp := int(0)
ch.try_pop(mut tmp)
assert tmp == 123
}