| ... | ... | @@ -6801,6 +6801,32 @@ test "peer type resolution: *const T and ?*T" { |
| 6801 | 6801 | try expect(a == b); |
| 6802 | 6802 | try expect(b == a); |
| 6803 | 6803 | } |
| 6804 | |
| 6805 | test "peer type resolution: error union switch" { |
| 6806 | // The non-error and error cases are only peers if the error case is just a switch expression; |
| 6807 | // the pattern `if (x) {...} else |err| blk: { switch (err) {...} }` does not consider the |
| 6808 | // non-error and error case to be peers. |
| 6809 | var a: error{ A, B, C }!u32 = 0; |
| 6810 | _ = &a; |
| 6811 | const b = if (a) |x| |
| 6812 | x + 3 |
| 6813 | else |err| switch (err) { |
| 6814 | error.A => 0, |
| 6815 | error.B => 1, |
| 6816 | error.C => null, |
| 6817 | }; |
| 6818 | try expect(@TypeOf(b) == ?u32); |
| 6819 | |
| 6820 | // The non-error and error cases are only peers if the error case is just a switch expression; |
| 6821 | // the pattern `x catch |err| blk: { switch (err) {...} }` does not consider the unwrapped `x` |
| 6822 | // and error case to be peers. |
| 6823 | const c = a catch |err| switch (err) { |
| 6824 | error.A => 0, |
| 6825 | error.B => 1, |
| 6826 | error.C => null, |
| 6827 | }; |
| 6828 | try expect(@TypeOf(c) == ?u32); |
| 6829 | } |
| 6804 | 6830 | {#code_end#} |
| 6805 | 6831 | {#header_close#} |
| 6806 | 6832 | {#header_close#} |