v2 / vlib / v / slow_tests / inout / comptime_iterate.vv
35 lines · 32 sloc · 530 bytes · 5043e14e355659f0232f770241694d8ff3a242c9
Raw
1type TestSum = int | string
2
3struct Bar {
4 y int
5}
6
7struct Foo {
8mut:
9 a TestSum
10 b int
11 c string
12 d Bar
13}
14
15fn main() {
16 $for f in Foo.fields {
17 $if f.typ is $sumtype {
18 dump(f.name)
19 $for f2 in f.variants {
20 $if f2.typ is $int {
21 assert f2.typ == typeof[int]().idx
22 dump('int')
23 } $else $if f2.typ is $string {
24 dump('string')
25 assert f2.typ == typeof[string]().idx
26 }
27 }
28 } $else $if f.typ is Bar {
29 $for f3 in f.fields {
30 assert f3.typ == typeof[int]().idx
31 dump(f3.name)
32 }
33 }
34 }
35}
36