v2 / vlib / v / tests / fns / closure_variable_in_smartcast_test.v
25 lines · 22 sloc · 418 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1pub type MyCallback = fn () | fn (ctx voidptr)
2
3fn my_lower_level_func(func fn (ctx voidptr), ctx voidptr) {
4 println('Bar')
5}
6
7fn my_func(cb MyCallback, ctx voidptr) {
8 my_lower_level_func(fn [cb] (ctx voidptr) {
9 match cb {
10 fn () {
11 cb()
12 }
13 fn (ctx voidptr) {
14 cb(ctx)
15 }
16 }
17 }, ctx)
18}
19
20fn test_closure_variable_in_smartcast() {
21 my_func(fn () {
22 println('Foo')
23 }, unsafe { nil })
24 assert true
25}
26