v4 / vlib / v / tests / aliases / alias_struct_ref_mut_capture_test.v
20 lines · 17 sloc · 247 bytes · d1b4f6507d7d93e897ac6fa20211cf87c9b9f67a
Raw
1struct App {
2mut:
3 score int
4}
5
6type AppRef = &App
7
8fn make_handler(mut app AppRef) fn () {
9 return fn [mut app] () {
10 app.score++
11 }
12}
13
14fn test_main() {
15 mut a := App{}
16 h := make_handler(mut &a)
17 assert a.score == 0
18 h()
19 assert a.score == 1
20}
21