| 1 | struct Point { |
| 2 | x int |
| 3 | y int |
| 4 | } |
| 5 | |
| 6 | struct Line { |
| 7 | p1 Point |
| 8 | p2 Point |
| 9 | } |
| 10 | |
| 11 | // Sum type |
| 12 | type ObjSumType = Line | Point |
| 13 | |
| 14 | fn test_print_smartcast_variable() { |
| 15 | // Type checking and casts |
| 16 | mut point := ObjSumType(Point{2, 5}) |
| 17 | |
| 18 | if point is Point { |
| 19 | println('Point') |
| 20 | } |
| 21 | |
| 22 | if point !is Point { |
| 23 | println('Not Point') |
| 24 | } |
| 25 | |
| 26 | if mut point is Point { |
| 27 | println(point) |
| 28 | assert point.str().contains('x: 2') |
| 29 | assert point.str().contains('y: 5') |
| 30 | assert '${point}'.contains('x: 2') |
| 31 | assert '${point}'.contains('y: 5') |
| 32 | } |
| 33 | } |
| 34 | |