v2 / vlib / v / tests / comptime / comptime_for_selector_test.v
23 lines · 21 sloc · 329 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Test {
2 b ?[]int
3}
4
5fn call_generic[U](val U) int {
6 mut out := 0
7 $for field in U.fields {
8 variable := val.$(field.name)
9 println(variable)
10 for element in val.$(field.name) {
11 dump(element)
12 out += element
13 }
14 }
15 return out
16}
17
18fn test_main() {
19 test := Test{
20 b: [1, 2, 3]
21 }
22 assert call_generic(test) == 6
23}
24