| 1 | module main |
| 2 | |
| 3 | struct Foo { |
| 4 | a int |
| 5 | } |
| 6 | |
| 7 | type SumType = Foo | int | string |
| 8 | |
| 9 | fn (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 | |
| 21 | fn test_main() { |
| 22 | assert SumType(1).cast[int](1) == 'v: 1' |
| 23 | } |
| 24 |