| 1 | interface Something { |
| 2 | i int |
| 3 | } |
| 4 | |
| 5 | struct Some { |
| 6 | i int |
| 7 | } |
| 8 | |
| 9 | struct App { |
| 10 | mut: |
| 11 | count u8 |
| 12 | } |
| 13 | |
| 14 | fn (mut self App) next[T](input T) string { |
| 15 | $if T is Something { |
| 16 | return 'Something' |
| 17 | } $else $if T is f64 { |
| 18 | return 'f64' |
| 19 | } $else { |
| 20 | panic('${typeof(T.typ).name} is not supported') |
| 21 | } |
| 22 | panic('Unreachable') |
| 23 | } |
| 24 | |
| 25 | fn test_comptime_if_is_interface() { |
| 26 | mut app := App{} |
| 27 | assert app.next(Something(Some{1})) == 'Something' |
| 28 | assert app.next(1.0) == 'f64' |
| 29 | } |
| 30 |