v2 / vlib / v / tests / comptime / comptime_smart_receiver_test.v
35 lines · 28 sloc · 502 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Context {
2}
3
4struct Input {
5}
6
7struct Block {
8 x int
9 y int
10mut:
11 children []Element
12}
13
14type Element = Block | Input
15
16fn (input Input) draw(mut ctx Context, x int, y int) {}
17
18fn (block Block) draw(mut ctx Context, x int, y int) {
19 for child in block.children {
20 child.draw(mut ctx, block.x + x, block.y + y)
21 }
22}
23
24fn (elt Element) draw(mut ctx Context, x int, y int) {
25 $for T in Element.variants {
26 if elt is T {
27 elt.draw(mut ctx, x, y)
28 return
29 }
30 }
31}
32
33fn test_main() {
34 assert true
35}
36