vxx2 / vlib / v / gen / c / testdata / autofree_comptime_selector_clone.vv
32 lines · 30 sloc · 561 bytes · 777460dfd3f7cf551cb57ac9a6f29831aa85f164
Raw
1// vtest vflags: -autofree
2struct Item {
3 name string
4 tags []string
5}
6
7fn process[T](val T) string {
8 mut result := ''
9 $for field in T.fields {
10 $if field.unaliased_typ is string {
11 name := val.$(field.name)
12 result += name
13 } $else $if field.unaliased_typ is []string {
14 arr := val.$(field.name)
15 for tag in arr {
16 result += tag
17 }
18 }
19 }
20 return result
21}
22
23fn main() {
24 item := Item{
25 name: 'test'
26 tags: ['a', 'b', 'c']
27 }
28 assert process(item) == 'testabc'
29 assert item.name == 'test'
30 assert item.tags == ['a', 'b', 'c']
31 println('ok')
32}
33