v2 / vlib / v / tests / comptime / comptime_variant_interp_test.v
23 lines · 19 sloc · 327 bytes · d1fdcfbab42cf9eec405fb5cf41869d5d2c1a7dc
Raw
1module main
2
3struct Foo {
4 a int
5}
6
7type SumType = Foo | int | string
8
9fn (v SumType) cast[T](val T) string {
10 mut res := ''
11 $for variant_value in v.variants {
12 if v is variant_value {
13 println('v: ${v}')
14 res = 'v: ${v}'
15 println(res)
16 }
17 }
18 return res
19}
20
21fn test_main() {
22 assert SumType(1).cast[int](1) == 'v: 1'
23}
24