Skip to content

Commit 9c91502

Browse files
committed
add default parameter value; add another test
1 parent ff225ed commit 9c91502

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

Sources/SwiftSyntaxMacroExpansion/MacroReplacement.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ extension MacroDeclSyntax {
398398
_ node: some FreestandingMacroExpansionSyntax,
399399
definition: MacroExpansionExprSyntax,
400400
replacements: [MacroDefinition.Replacement],
401-
genericReplacements: [MacroDefinition.GenericArgumentReplacement]
401+
genericReplacements: [MacroDefinition.GenericArgumentReplacement] = []
402402
) -> ExprSyntax {
403403
return expand(
404404
argumentList: node.arguments,

Tests/SwiftSyntaxMacroExpansionTest/MacroReplacementTests.swift

+34
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,38 @@ final class MacroReplacementTests: XCTestCase {
267267
"""
268268
)
269269
}
270+
271+
func testMacroGenericArgumentExpansion_array() throws {
272+
let macro: DeclSyntax =
273+
"""
274+
macro gen(a: Array<Int>) = #other<A>(first: a)
275+
"""
276+
277+
let use: ExprSyntax =
278+
"""
279+
#otheren<Int>(a: [1, 2, 3])
280+
"""
281+
282+
let macroDecl = macro.as(MacroDeclSyntax.self)!
283+
let definition = try macroDecl.checkDefinition()
284+
guard case let .expansion(expansion, replacements, genericReplacements) = definition else {
285+
XCTFail("not a normal expansion")
286+
return
287+
}
288+
289+
XCTAssertEqual(genericReplacements.count, 0)
290+
291+
let expandedSyntax = macroDecl.expand(
292+
use.as(MacroExpansionExprSyntax.self)!,
293+
definition: expansion,
294+
replacements: replacements,
295+
genericReplacements: genericReplacements
296+
)
297+
assertStringsEqualWithDiff(
298+
expandedSyntax.description,
299+
"""
300+
#other<A>(first: [1, 2, 3])
301+
"""
302+
)
303+
}
270304
}

0 commit comments

Comments
 (0)