|
1 | | -// RUN: %target-swift-frontend -enable-copy-propagation=requested-passes-only -emit-sil -primary-file %s -o /dev/null -verify |
| 1 | +// RUN: %target-swift-emit-sil -enable-copy-propagation=requested-passes-only -primary-file %s -o /dev/null -verify |
2 | 2 |
|
3 | 3 | import Swift |
4 | 4 |
|
@@ -1667,3 +1667,52 @@ final class HasInitAccessors { |
1667 | 1667 | ints.append(0) |
1668 | 1668 | } |
1669 | 1669 | } |
| 1670 | + |
| 1671 | +// https://github.com/swiftlang/swift/issues/74478 |
| 1672 | + |
| 1673 | +func structurallyUninhabitedLvalueSwitch() { |
| 1674 | + |
| 1675 | + enum NeverEver {} |
| 1676 | + |
| 1677 | + func gh_74478() { |
| 1678 | + let x: Never // expected-note {{constant defined here}} |
| 1679 | + switch x {} // expected-error {{constant 'x' used before being initialized}} |
| 1680 | + } |
| 1681 | + |
| 1682 | + func nested_switch() { |
| 1683 | + let x: Never // expected-note {{constant defined here}} |
| 1684 | + let y: Never = switch () { |
| 1685 | + default: |
| 1686 | + switch x { // expected-error {{constant 'x' used before being initialized}} |
| 1687 | + default: x |
| 1688 | + } |
| 1689 | + } |
| 1690 | + _ = y |
| 1691 | + } |
| 1692 | + |
| 1693 | + func customNever() { |
| 1694 | + let x: NeverEver // expected-note {{constant defined here}} |
| 1695 | + switch x {} // expected-error {{constant 'x' used before being initialized}} |
| 1696 | + } |
| 1697 | + |
| 1698 | + func structurallyUninhabited() { |
| 1699 | + let x: (Int, Never, Bool) // expected-note {{constant defined here}} |
| 1700 | + switch x {} // expected-error {{constant 'x.0' used before being initialized}} |
| 1701 | + } |
| 1702 | + |
| 1703 | + func structurallyUninhabited_variant1() { |
| 1704 | + let x: (Int, NeverEver, Bool) // expected-note {{constant defined here}} |
| 1705 | + switch x.2 { default: fatalError() } // expected-error {{constant 'x.2' used before being initialized}} |
| 1706 | + } |
| 1707 | +} |
| 1708 | + |
| 1709 | +protocol P_74478 { |
| 1710 | + associatedtype A |
| 1711 | +} |
| 1712 | + |
| 1713 | +extension P_74478 where A == (Int, (Bool, Never)) { |
| 1714 | + func structurallyUninhabitedGenericIndirection() { |
| 1715 | + let x: A // expected-note {{constant defined here}} |
| 1716 | + switch x {} // expected-error {{constant 'x.0' used before being initialized}} |
| 1717 | + } |
| 1718 | +} |
0 commit comments