1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/v/tests/comptime_if_is_interface_test.v

30 lines
442 B
V

interface Something {
i int
}
struct Some {
i int
}
struct App {
mut:
count u8
}
fn (mut self App) next<T>(input T) string {
$if T is Something {
return 'Something'
} $else $if T is f64 {
return 'f64'
} $else {
panic('${typeof(T.typ).name} is not supported')
}
panic('Unreachable')
}
fn test_comptime_if_is_interface() {
mut app := App{}
assert app.next(Something(Some{1})) == 'Something'
assert app.next(1.0) == 'f64'
}