v2 / vlib / v / tests / comptime / comptime_if_is_interface_test.v
29 lines · 25 sloc · 442 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1interface Something {
2 i int
3}
4
5struct Some {
6 i int
7}
8
9struct App {
10mut:
11 count u8
12}
13
14fn (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
25fn 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