Skip to content

Commit

Permalink
Fix compile error caused by wildcard argument usage (#130)
Browse files Browse the repository at this point in the history
* Fix compile error caused by wildcard argument usage

* Apply suggestions from code review

---------

Co-authored-by: hanjun-yu <[email protected]>
Co-authored-by: Stephen Celis <[email protected]>
  • Loading branch information
3 people authored Nov 15, 2023
1 parent 73b69bd commit ed7facd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/CasePathsMacros/CasePathableMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ extension EnumCaseElementListSyntax.Element {
for index in associatedValue.parameters.indices {
associatedValue.parameters[index].type.trailingTrivia = ""
associatedValue.parameters[index].defaultValue = nil
if associatedValue.parameters[index].firstName?.tokenKind == .wildcard {
associatedValue.parameters[index].colon = nil
associatedValue.parameters[index].firstName = nil
associatedValue.parameters[index].secondName = nil
}
}
return "(\(associatedValue.parameters.trimmed))"
}
Expand Down
34 changes: 34 additions & 0 deletions Tests/CasePathsMacrosTests/CasePathableMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,40 @@ final class CasePathableMacroTests: XCTestCase {
"""
}
}

func testWildcard() {
assertMacro {
"""
@CasePathable enum Foo {
case bar(_ int: Int, _ bool: Bool)
}
"""
} expansion: {
"""
enum Foo {
case bar(_ int: Int, _ bool: Bool)
struct AllCasePaths {
var bar: CasePaths.AnyCasePath<Foo, (Int, Bool)> {
CasePaths.AnyCasePath<Foo, (Int, Bool)>(
embed: Foo.bar,
extract: {
guard case let .bar(v0, v1) = $0 else {
return nil
}
return (v0, v1)
}
)
}
}
static var allCasePaths: AllCasePaths { AllCasePaths() }
}
extension Foo: CasePaths.CasePathable {
}
"""
}
}

func testSelf() {
assertMacro {
Expand Down

0 comments on commit ed7facd

Please sign in to comment.