| author | |
| committer | |
| log | 31ed8d293ddb79d34306e0b23e76d8a361c8856f |
| tree | 6058e6849762e925518b5b64cbf800643f248290 |
| parent | b9c2837c1c9eddc903aeeb168b8d2daa48837ddb |
Closes #140772 files changed, 31 insertions(+), 0 deletions(-)
src/Sema.zig+19| ... | @@ -29761,6 +29761,25 @@ fn resolvePeerTypes( | ... | @@ -29761,6 +29761,25 @@ fn resolvePeerTypes( |
| 29761 | continue; | 29761 | continue; |
| 29762 | } | 29762 | } |
| 29763 | }, | 29763 | }, |
| 29764 | .ErrorSet => { | ||
| 29765 | chosen = candidate; | ||
| 29766 | chosen_i = candidate_i + 1; | ||
| 29767 | if (err_set_ty) |chosen_set_ty| { | ||
| 29768 | if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, chosen_set_ty, chosen_ty, src, src)) { | ||
| 29769 | continue; | ||
| 29770 | } | ||
| 29771 | if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, chosen_ty, chosen_set_ty, src, src)) { | ||
| 29772 | err_set_ty = chosen_ty; | ||
| 29773 | continue; | ||
| 29774 | } | ||
| 29775 | |||
| 29776 | err_set_ty = try chosen_set_ty.errorSetMerge(sema.arena, chosen_ty); | ||
| 29777 | continue; | ||
| 29778 | } else { | ||
| 29779 | err_set_ty = chosen_ty; | ||
| 29780 | continue; | ||
| 29781 | } | ||
| 29782 | }, | ||
| 29764 | else => {}, | 29783 | else => {}, |
| 29765 | } | 29784 | } |
| 29766 | 29785 |
test/behavior/cast.zig+12| ... | @@ -1541,3 +1541,15 @@ test "single item pointer to pointer to array to slice" { | ... | @@ -1541,3 +1541,15 @@ test "single item pointer to pointer to array to slice" { |
| 1541 | const z1 = @as([]const i32, @as(*[1]i32, &x)); | 1541 | const z1 = @as([]const i32, @as(*[1]i32, &x)); |
| 1542 | try expect(z1[0] == 1234); | 1542 | try expect(z1[0] == 1234); |
| 1543 | } | 1543 | } |
| 1544 | |||
| 1545 | test "peer type resolution forms error union" { | ||
| 1546 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO | ||
| 1547 | |||
| 1548 | var foo: i32 = 123; | ||
| 1549 | const result = if (foo < 0) switch (-foo) { | ||
| 1550 | 0 => unreachable, | ||
| 1551 | 42 => error.AccessDenied, | ||
| 1552 | else => unreachable, | ||
| 1553 | } else @intCast(u32, foo); | ||
| 1554 | try expect(try result == 123); | ||
| 1555 | } |