Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compile error caused by wildcard argument usage #130

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
stephencelis marked this conversation as resolved.
Show resolved Hide resolved
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