v2 / vlib / v / tests / casts / autocast_in_if_conds_2_test.v
32 lines · 26 sloc · 399 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1type MySumType = S1 | S2
2
3struct Info {
4 name string
5}
6
7struct S1 {
8 is_info bool
9 info Info
10}
11
12struct S2 {
13 field2 string
14}
15
16fn get_name(name string) string {
17 return name
18}
19
20fn test_autocast_in_if_conds() {
21 s := MySumType(S1{
22 is_info: false
23 info: Info{'foo'}
24 })
25
26 if s is S1 && !s.is_info && get_name(s.info.name) == 'foo' {
27 println('ok')
28 assert true
29 } else {
30 assert false
31 }
32}
33