| 1 | import os |
| 2 | |
| 3 | fn test_for_in_option() { |
| 4 | for d in os.read_lines(@FILE) or { panic('not found') } { |
| 5 | println(d) |
| 6 | } |
| 7 | assert true |
| 8 | } |
| 9 | |
| 10 | // for issue 20528 |
| 11 | // phenomenon: when the cond expr is SelectorExpr and the type is an array, cgen fails. |
| 12 | struct Foo { |
| 13 | data ?[]int |
| 14 | } |
| 15 | |
| 16 | fn (f Foo) get_first() ?int { |
| 17 | for d in f.data or { return none } { |
| 18 | return d |
| 19 | } |
| 20 | return none |
| 21 | } |
| 22 | |
| 23 | fn test_cond_is_selector_array_and_with_or_block() { |
| 24 | foo := Foo{ |
| 25 | data: [1, 2, 3] |
| 26 | } |
| 27 | assert foo.get_first()? == 1 |
| 28 | } |
| 29 | |