| 1 | struct Foo1 { |
| 2 | arr1 [5]?int |
| 3 | arr2 [5]int |
| 4 | } |
| 5 | |
| 6 | fn get_has_option_fixed() ?int { |
| 7 | foo := Foo1{} |
| 8 | return foo.arr1[0] |
| 9 | } |
| 10 | |
| 11 | fn get_no_option_fixed() int { |
| 12 | foo := Foo1{} |
| 13 | return foo.arr2[0] |
| 14 | } |
| 15 | |
| 16 | fn test_option_fixed() { |
| 17 | x := get_has_option_fixed() or { 0 } |
| 18 | assert x == 0 |
| 19 | assert get_no_option_fixed() == 0 |
| 20 | } |
| 21 | |
| 22 | struct Foo2 { |
| 23 | mut: |
| 24 | arr1 []?int |
| 25 | arr2 []int |
| 26 | } |
| 27 | |
| 28 | fn get_has_option() ?int { |
| 29 | mut foo := Foo2{} |
| 30 | foo.arr1 << 0 |
| 31 | return foo.arr1[0] |
| 32 | } |
| 33 | |
| 34 | fn get_no_option() int { |
| 35 | mut foo := Foo2{} |
| 36 | foo.arr2 << 0 |
| 37 | return foo.arr2[0] |
| 38 | } |
| 39 | |
| 40 | fn test_option_non_fixed() { |
| 41 | x := get_has_option()? |
| 42 | assert x == 0 |
| 43 | assert get_no_option() == 0 |
| 44 | } |
| 45 | |