| 1 | fn unwrap(a ?[3]u8) { |
| 2 | if a == none { |
| 3 | println('${@FN}:${@LINE}: ${typeof(a).name}') |
| 4 | assert typeof(a).name == '?[3]u8' |
| 5 | } else { |
| 6 | println('${@FN}:${@LINE}: ${typeof(a).name}') |
| 7 | assert typeof(a).name == '[3]u8' |
| 8 | } |
| 9 | if a != none { |
| 10 | println('${@FN}:${@LINE}: ${typeof(a).name}') |
| 11 | assert typeof(a).name == '[3]u8' |
| 12 | } else { |
| 13 | println('${@FN}:${@LINE}: ${typeof(a).name}') |
| 14 | assert typeof(a).name == '?[3]u8' |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | struct Opt { |
| 19 | pub mut: |
| 20 | f ?[3]u8 |
| 21 | } |
| 22 | |
| 23 | struct Issue23611Foo { |
| 24 | mut: |
| 25 | test bool |
| 26 | } |
| 27 | |
| 28 | fn unwrap_field(opt Opt) { |
| 29 | if opt.f == none { |
| 30 | println('${@FN}:${@LINE}: ${typeof(opt.f).name}') |
| 31 | assert opt.f == ?[3]u8(none) |
| 32 | assert typeof(opt.f).name == '?[3]u8' |
| 33 | } else { |
| 34 | println('${@FN}:${@LINE}: ${typeof(opt.f).name}') |
| 35 | assert opt.f == [u8(2), 2, 2]! |
| 36 | assert typeof(opt.f).name == '[3]u8' |
| 37 | } |
| 38 | if opt.f != none { |
| 39 | println('${@FN}:${@LINE}: ${typeof(opt.f).name}') |
| 40 | assert opt.f == [u8(2), 2, 2]! |
| 41 | assert typeof(opt.f).name == '[3]u8' |
| 42 | } else { |
| 43 | println('${@FN}:${@LINE}: ${typeof(opt.f).name}') |
| 44 | assert opt.f == ?[3]u8(none) |
| 45 | assert typeof(opt.f).name == '?[3]u8' |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | fn test_main() { |
| 50 | mut a := ?[3]u8(none) |
| 51 | unwrap(a) |
| 52 | a = [3]u8{init: 1} |
| 53 | unwrap(a) |
| 54 | |
| 55 | mut f := Opt{} |
| 56 | unwrap_field(f) |
| 57 | f.f = [3]u8{init: 2} |
| 58 | unwrap_field(f) |
| 59 | } |
| 60 | |
| 61 | fn test_option_smartcast_after_non_option_assignment() { |
| 62 | mut foo := ?Issue23611Foo(none) |
| 63 | if foo == none { |
| 64 | foo = Issue23611Foo{} |
| 65 | foo.test = true |
| 66 | } |
| 67 | assert foo != none |
| 68 | assert foo?.test |
| 69 | } |
| 70 | |