vxx / vlib / v / tests / interfaces / interface_var_selector_test.v
28 lines · 21 sloc · 407 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1interface Module {
2 import_()
3}
4
5struct TestModule {}
6
7fn (mod TestModule) import_() {
8 println("I'm called!")
9}
10
11fn t_func(a voidptr, b &char) bool {
12 return true
13}
14
15fn import_module[T]() bool {
16 $if T !is Module {
17 println("Type doesn't implement Module.")
18 return
19 }
20
21 mod := Module(T{})
22
23 return t_func(mod.import_, &char(T.name.str))
24}
25
26fn test_main() {
27 assert import_module[TestModule]() == true
28}
29