| 1 | // vtest vflags: -gc boehm |
| 2 | const issue_27329_kind_false = 0 |
| 3 | const issue_27329_kind_true = 1 |
| 4 | const issue_27329_kind_len = 2 |
| 5 | |
| 6 | struct Issue27329Object { |
| 7 | kind int |
| 8 | ival int |
| 9 | len_val int |
| 10 | child &Issue27329Object |
| 11 | } |
| 12 | |
| 13 | fn (obj &Issue27329Object) truthy() bool { |
| 14 | return if obj.kind == issue_27329_kind_true { |
| 15 | true |
| 16 | } else if obj.kind == issue_27329_kind_len { |
| 17 | obj.len_val > 0 |
| 18 | } else { |
| 19 | false |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | fn issue_27329_objects() []&Issue27329Object { |
| 24 | return [ |
| 25 | &Issue27329Object{ |
| 26 | kind: issue_27329_kind_false |
| 27 | ival: 0 |
| 28 | len_val: 0 |
| 29 | child: unsafe { nil } |
| 30 | }, |
| 31 | &Issue27329Object{ |
| 32 | kind: issue_27329_kind_true |
| 33 | ival: 1 |
| 34 | len_val: 0 |
| 35 | child: unsafe { nil } |
| 36 | }, |
| 37 | &Issue27329Object{ |
| 38 | kind: issue_27329_kind_len |
| 39 | ival: 2 |
| 40 | len_val: 3 |
| 41 | child: unsafe { nil } |
| 42 | }, |
| 43 | ] |
| 44 | } |
| 45 | |
| 46 | fn issue_27329_nested() &Issue27329Object { |
| 47 | return &Issue27329Object{ |
| 48 | kind: issue_27329_kind_len |
| 49 | ival: 7 |
| 50 | len_val: 1 |
| 51 | child: &Issue27329Object{ |
| 52 | kind: issue_27329_kind_false |
| 53 | ival: 8 |
| 54 | len_val: 0 |
| 55 | child: unsafe { nil } |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | fn main() { |
| 61 | objects := issue_27329_objects() |
| 62 | nested := issue_27329_nested() |
| 63 | assert !objects[0].truthy() |
| 64 | assert objects[1].truthy() |
| 65 | assert objects[2].truthy() |
| 66 | assert nested.truthy() |
| 67 | assert !nested.child.truthy() |
| 68 | println('ok') |
| 69 | } |
| 70 | |