From ed7facdd4a361514b46e3bbc6238cd41c84be4ec Mon Sep 17 00:00:00 2001 From: HanjunYu Date: Thu, 16 Nov 2023 03:19:32 +0900 Subject: [PATCH] Fix compile error caused by wildcard argument usage (#130) * Fix compile error caused by wildcard argument usage * Apply suggestions from code review --------- Co-authored-by: hanjun-yu Co-authored-by: Stephen Celis --- .../CasePathsMacros/CasePathableMacro.swift | 5 +++ .../CasePathableMacroTests.swift | 34 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/Sources/CasePathsMacros/CasePathableMacro.swift b/Sources/CasePathsMacros/CasePathableMacro.swift index cf2e483a..aa511f69 100644 --- a/Sources/CasePathsMacros/CasePathableMacro.swift +++ b/Sources/CasePathsMacros/CasePathableMacro.swift @@ -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))" } diff --git a/Tests/CasePathsMacrosTests/CasePathableMacroTests.swift b/Tests/CasePathsMacrosTests/CasePathableMacroTests.swift index 2ee60aa9..5d2a4938 100644 --- a/Tests/CasePathsMacrosTests/CasePathableMacroTests.swift +++ b/Tests/CasePathsMacrosTests/CasePathableMacroTests.swift @@ -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 { + CasePaths.AnyCasePath( + 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 {