| ... | ... | @@ -1542,3 +1542,40 @@ test "error captures narrow error sets" { |
| 1542 | 1542 | try comptime S.doTheTest(error.B); |
| 1543 | 1543 | try comptime S.doTheTest(error.C); |
| 1544 | 1544 | } |
| 1545 | |
| 1546 | test "repeated switch analysis overrides previous analysis results" { |
| 1547 | // This tests an implementation detail where semantic analysis of switch |
| 1548 | // statements uses the switch inst itself to store capture values and result |
| 1549 | // type information while analyzing (parts of) that switch inst. |
| 1550 | // If that inst has already been assigned a result by a previous analysis |
| 1551 | // that result needs to be overwritten. |
| 1552 | |
| 1553 | comptime { |
| 1554 | const x: u32 = 123; |
| 1555 | for (0..2) |_| _ = switch (x) { |
| 1556 | 123 => |capture| capture, |
| 1557 | else => unreachable, |
| 1558 | }; |
| 1559 | } |
| 1560 | comptime { |
| 1561 | const x: union(enum) { a, b, c } = .a; |
| 1562 | for (0..2) |_| _ = switch (x) { |
| 1563 | .a => |_, tag| tag, |
| 1564 | else => unreachable, |
| 1565 | }; |
| 1566 | } |
| 1567 | comptime { |
| 1568 | const x: enum { a, b, c } = .a; |
| 1569 | for (0..2) |_| _ = label: switch (x) { |
| 1570 | .a => continue :label .b, |
| 1571 | else => 123, |
| 1572 | }; |
| 1573 | } |
| 1574 | comptime { |
| 1575 | const x: anyerror!void = error.MyError; |
| 1576 | for (0..2) |_| _ = x catch |err| switch (err) { |
| 1577 | error.MyError => {}, |
| 1578 | else => unreachable, |
| 1579 | }; |
| 1580 | } |
| 1581 | } |