| 1 | struct Foo { |
| 2 | option ?int = unsafe { none } |
| 3 | } |
| 4 | |
| 5 | fn test_main() { |
| 6 | test := true |
| 7 | foo := Foo{} |
| 8 | result := foo.option or { |
| 9 | match test { |
| 10 | true { 1 } |
| 11 | else { 2 } |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | assert result == 1 |
| 16 | } |
| 17 | |
| 18 | struct Issue17850Error { |
| 19 | Error |
| 20 | } |
| 21 | |
| 22 | struct Issue17850Data { |
| 23 | pub: |
| 24 | name string |
| 25 | } |
| 26 | |
| 27 | fn (_ &Issue17850Error) msg() string { |
| 28 | return 'issue 17850' |
| 29 | } |
| 30 | |
| 31 | fn issue17850_do_thing(name string, fail bool) !Issue17850Data { |
| 32 | if fail { |
| 33 | return Issue17850Error{} |
| 34 | } |
| 35 | return Issue17850Data{ |
| 36 | name: name |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | fn test_result_or_block_match_error_type() { |
| 41 | data := issue17850_do_thing('my_db', true) or { |
| 42 | match err { |
| 43 | Issue17850Error { |
| 44 | Issue17850Data{ |
| 45 | name: 'my_db' |
| 46 | } |
| 47 | } |
| 48 | else { |
| 49 | panic(err) |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | assert data == Issue17850Data{ |
| 54 | name: 'my_db' |
| 55 | } |
| 56 | } |
| 57 | |