| 1 | struct Foo { |
| 2 | name ?string |
| 3 | } |
| 4 | |
| 5 | fn test_option_var() { |
| 6 | foo := Foo{} |
| 7 | other := foo.name |
| 8 | |
| 9 | println(typeof(other).name) |
| 10 | if name := other { |
| 11 | println('with name: ${name}') |
| 12 | assert false |
| 13 | } else { |
| 14 | println('without name') |
| 15 | assert true |
| 16 | } |
| 17 | |
| 18 | mut counter := 0 |
| 19 | val := other or { |
| 20 | counter++ |
| 21 | 'default' |
| 22 | } |
| 23 | |
| 24 | assert val == 'default' |
| 25 | assert counter == 1 |
| 26 | } |
| 27 |