v2 / vlib / v / tests / interfaces / interface_edge_cases / i9_test.v
35 lines · 30 sloc · 750 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1// The series of i?_test.v files, do test different edge cases for
2// interface table generation. The differences may seem very minor
3// (placement of the interface declaration, whether or not there are
4// helper methods, etc), but PLEASE do NOT be tempted to merge them in
5// a single _test.v file. Debugging interface code generation issues
6// is *much easier* when the _test.v files are very short and focused.
7struct Point {
8 x i8
9 y i8
10}
11
12fn (p Point) draw() string {
13 return 'Point(${p.x},${p.y})'
14}
15
16fn to_string(d Drawer) {
17 println(d.draw())
18}
19
20interface Drawer {
21 draw() string
22}
23
24fn to_string_generic[T](t T) {
25 to_string(t)
26}
27
28fn test_to_string_generic_can_be_called() {
29 p := Point{
30 x: 2
31 y: 3
32 }
33 to_string_generic(p)
34 assert true
35}
36