mirror of
https://github.com/vlang/v.git
synced 2025-09-17 11:26:17 -04:00
cgen: fix closure variable in smartcast (#19796)
This commit is contained in:
parent
60ba14038a
commit
cd5c5561db
@ -1777,7 +1777,11 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
|
||||
cast_sym := g.table.sym(g.unwrap_generic(typ))
|
||||
mut is_ptr := false
|
||||
if i == 0 {
|
||||
g.write(node.name)
|
||||
if obj.is_inherited {
|
||||
g.write(c.closure_ctx + '->' + node.name)
|
||||
} else {
|
||||
g.write(node.name)
|
||||
}
|
||||
if obj.orig_type.is_ptr() {
|
||||
is_ptr = true
|
||||
}
|
||||
|
25
vlib/v/tests/closure_variable_in_smartcast_test.v
Normal file
25
vlib/v/tests/closure_variable_in_smartcast_test.v
Normal file
@ -0,0 +1,25 @@
|
||||
pub type MyCallback = fn () | fn (ctx voidptr)
|
||||
|
||||
fn my_lower_level_func(func fn (ctx voidptr), ctx voidptr) {
|
||||
println('Bar')
|
||||
}
|
||||
|
||||
fn my_func(cb MyCallback, ctx voidptr) {
|
||||
my_lower_level_func(fn [cb] (ctx voidptr) {
|
||||
match cb {
|
||||
fn () {
|
||||
cb()
|
||||
}
|
||||
fn (ctx voidptr) {
|
||||
cb(ctx)
|
||||
}
|
||||
}
|
||||
}, ctx)
|
||||
}
|
||||
|
||||
fn test_closure_variable_in_smartcast() {
|
||||
my_func(fn () {
|
||||
println('Foo')
|
||||
}, unsafe { nil })
|
||||
assert true
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user