Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix build warning when
@CasePathable
is applied to enums with no ca…
…ses (#164) * Fix build warning when `@CasePathable` is applied to enums with no cases Fixes warnings due to unreachable code: For example: ```swift @CasePathable enum Foo {} ``` Produces this expansion (compiler warnings added as code comments by me) ```swift enum Foo: CasePathable { public struct AllCasePaths: Sequence { public subscript(root: Foo) -> PartialCaseKeyPath<Foo> { return \.never //⚠️ warning: will never be executed // 'root' is of type 'Foo' which cannot be constructed because it // is an enum with no cases } public func makeIterator() -> IndexingIterator<[PartialCaseKeyPath<Foo>]> { let allCasePaths: [PartialCaseKeyPath<Foo>] = [] return allCasePaths.makeIterator() } } public static var allCasePaths: AllCasePaths { AllCasePaths() } } ``` We can fix this warning by simply not producing the subscript definition when the enum has no cases. * Omit return statement for enums without cases
- Loading branch information