v2 / vlib / v / tests / comptime / comptime_closure_field_access_test.v
23 lines · 21 sloc · 249 bytes · 5ac3852c944a7b2065ef231a3c628f89038b4491
Raw
1struct TestObj {
2mut:
3 a int
4 b int
5}
6
7fn test_main() {
8 x := &TestObj{
9 a: 1
10 b: 1
11 }
12 $for field in TestObj.fields {
13 run_fn(fn [x, field] () {
14 (*x).$(field.name) += 1
15 })
16 }
17 assert x.a == 2
18 assert x.b == 2
19}
20
21fn run_fn(f fn ()) {
22 f()
23}
24