| 1 | struct Data { |
| 2 | a ?int |
| 3 | b ?int = 1 |
| 4 | } |
| 5 | |
| 6 | struct Data2 { |
| 7 | d Data |
| 8 | } |
| 9 | |
| 10 | fn test_nested_option_struct_init() { |
| 11 | d2 := Data2{} |
| 12 | println(d2) |
| 13 | assert d2.d.a == none |
| 14 | assert d2.d.b != none |
| 15 | assert d2.d.b? == 1 |
| 16 | } |
| 17 | |
| 18 | struct AA { |
| 19 | bb ?BB // defaults to none |
| 20 | } |
| 21 | |
| 22 | struct BB { |
| 23 | x string @[required] |
| 24 | } |
| 25 | |
| 26 | fn test_nested_option_struct_with_attr_init() { |
| 27 | aa := AA{} |
| 28 | println(aa) |
| 29 | assert aa.bb == none |
| 30 | } |
| 31 |