v2 / vlib / v / tests / fns / lambda_expr_with_mut_param_test.v
29 lines · 26 sloc · 512 bytes · e2e5cf8db56f3562c7baa735061690be936bdf3e
Raw
1struct Window {
2mut:
3 calls int
4 on_init fn (mut w main.Window) = unsafe { nil }
5 cb fn (mut w main.Window, x int) = unsafe { nil }
6}
7
8fn (mut w Window) run() {
9 w.on_init(mut w)
10 w.cb(mut w, w.calls)
11}
12
13fn (mut w Window) method_with_mut_receiver() {
14 w.calls++
15}
16
17fn test_mut_lambda_expr() {
18 mut window := Window{
19 on_init: |mut w| w.method_with_mut_receiver()
20 cb: |mut w, mut y| unsafe {
21 if true {
22 assert y == 1
23 w.calls++
24 }
25 }
26 }
27 window.run()
28 assert window.calls == 2
29}
30