pointfreeco / swift-case-paths

🧰 Case paths extends the key path hierarchy to enum cases.
https://www.pointfree.co/collections/enums-and-structs/case-paths
MIT License
904 stars 105 forks source link

Handle comments on cases without associated values #163

Closed twocentstudios closed 3 months ago

twocentstudios commented 3 months ago

Fixes compilation error for enum cases without associated values that have trailing comments e.g.:

// Using swift-case-paths 1.4.1
@CasePathable enum Foo {
  case fizz(buzz: String) // Comment on case ✅
  case fizziest // Comment without associated value ❌ 
}

Previously, for trailing comments on enum cases without associated values, the macro was generating invalid syntax in ~two~ one place (the first was fixed by #162):

// public struct AllCasePaths: Sequence {
case .fizziest // Comment without associated value: return \.fizziest ❌

// public func makeIterator() -> IndexingIterator<[PartialCaseKeyPath<Foo>]> {
allCasePaths.append(\.fizziest // Comment without associated value) ❌

I used the same fix from #160 – adding .text. This has the side-effect of removing C-style comments outside the root enum declaration as mentioned in this comment, which I believe is not a problem.

twocentstudios commented 3 months ago

(I'm not particularly versed in writing macros, so feel free to close this PR if you have a better solution 🙆‍♂️)