v2 / vlib / v / tests / casts / autocast_in_if_conds_3_test.v
45 lines · 36 sloc · 574 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1type MySumType = S1 | S2
2
3struct Info {
4 name string
5}
6
7struct Node {
8 left MySumType
9}
10
11struct S1 {
12 is_info bool
13 info Info
14}
15
16fn (s1 S1) is_info() bool {
17 return s1.is_info
18}
19
20struct S2 {
21 field2 string
22}
23
24fn get_name(name string) string {
25 return name
26}
27
28fn test_autocast_in_if_conds() {
29 node := Node{
30 left: MySumType(S1{
31 is_info: false
32 info: Info{'foo'}
33 })
34 }
35
36 a := 22
37
38 if a > 0 && node.left is S1 && !node.left.is_info && get_name(node.left.info.name) == 'foo'
39 && !node.left.is_info() {
40 println('ok')
41 assert true
42 } else {
43 assert false
44 }
45}
46