v2 / vlib / v / tests / comptime / comptime_var_is_check_test.v
19 lines · 17 sloc · 318 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1type TestSum = int | string
2
3fn gen[T, R](sum T) R {
4 $if T is $sumtype {
5 $for v in sum.variants {
6 if sum is v {
7 $if sum is R {
8 return sum
9 }
10 }
11 }
12 }
13 return R{}
14}
15
16fn test_main() {
17 assert dump(gen[TestSum, string](TestSum('foo'))) == 'foo'
18 assert dump(gen[TestSum, int](TestSum(123))) == 123
19}
20