v2 / vlib / v / tests / fns / fn_ptr_call_test.v
22 lines · 20 sloc · 293 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Animal {
2mut:
3 age fn (p int) int = unsafe { nil }
4 duck Duck
5}
6
7struct Duck {
8mut:
9 age &fn (p int) int = unsafe { nil }
10}
11
12fn test_main() {
13 mut animal := Animal{
14 age: fn (x int) int {
15 return 5
16 }
17 }
18 animal.duck = Duck{
19 age: &animal.age
20 }
21 assert animal.duck.age(1) == 5
22}
23