v2 / vlib / v / tests / fns / method_call_on_aggregate_test.v
28 lines · 22 sloc · 302 bytes · 8e35f4d9848f7ad35d857a187dddbfd2eca5e19d
Raw
1type SumType = AA | BB
2
3struct AA {}
4
5struct BB {}
6
7fn (a &AA) foo() int {
8 println('AA.foo()')
9 return 200
10}
11
12fn (b &BB) foo() int {
13 println('BB.foo()')
14 return 100
15}
16
17fn test_main() {
18 x := SumType(BB{})
19 match x {
20 AA, BB {
21 ret := x.foo()
22 assert ret == 100
23 return
24 }
25 }
26
27 assert false
28}
29