Skip to content

Commit ed7facd

Browse files
hj56775hanjun-yustephencelis
authored
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 <[email protected]> Co-authored-by: Stephen Celis <[email protected]>
1 parent 73b69bd commit ed7facd

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

Sources/CasePathsMacros/CasePathableMacro.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ extension EnumCaseElementListSyntax.Element {
257257
for index in associatedValue.parameters.indices {
258258
associatedValue.parameters[index].type.trailingTrivia = ""
259259
associatedValue.parameters[index].defaultValue = nil
260+
if associatedValue.parameters[index].firstName?.tokenKind == .wildcard {
261+
associatedValue.parameters[index].colon = nil
262+
associatedValue.parameters[index].firstName = nil
263+
associatedValue.parameters[index].secondName = nil
264+
}
260265
}
261266
return "(\(associatedValue.parameters.trimmed))"
262267
}

Tests/CasePathsMacrosTests/CasePathableMacroTests.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,40 @@ final class CasePathableMacroTests: XCTestCase {
299299
"""
300300
}
301301
}
302+
303+
func testWildcard() {
304+
assertMacro {
305+
"""
306+
@CasePathable enum Foo {
307+
case bar(_ int: Int, _ bool: Bool)
308+
}
309+
"""
310+
} expansion: {
311+
"""
312+
enum Foo {
313+
case bar(_ int: Int, _ bool: Bool)
314+
315+
struct AllCasePaths {
316+
var bar: CasePaths.AnyCasePath<Foo, (Int, Bool)> {
317+
CasePaths.AnyCasePath<Foo, (Int, Bool)>(
318+
embed: Foo.bar,
319+
extract: {
320+
guard case let .bar(v0, v1) = $0 else {
321+
return nil
322+
}
323+
return (v0, v1)
324+
}
325+
)
326+
}
327+
}
328+
static var allCasePaths: AllCasePaths { AllCasePaths() }
329+
}
330+
331+
extension Foo: CasePaths.CasePathable {
332+
}
333+
"""
334+
}
335+
}
302336

303337
func testSelf() {
304338
assertMacro {

0 commit comments

Comments
 (0)