Skip to content

Commit 1ea916e

Browse files
committed
[CompilerPlugin/Macros] Pass macro syntax using _openExistential
To make it compatible pre Swift 5.7 compilers. `expansion(of:in:)` receives generic parameter.
1 parent 857111a commit 1ea916e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Sources/SwiftCompilerPlugin/Macros.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,17 @@ extension CompilerPlugin {
6060

6161
switch macroDefinition {
6262
case let exprMacroDef as ExpressionMacro.Type:
63-
let rewritten = try exprMacroDef.expansion(of: macroSyntax, in: context)
63+
func _expand<Node: FreestandingMacroExpansionSyntax>(node: Node) throws -> ExprSyntax {
64+
try exprMacroDef.expansion(of: node, in: context)
65+
}
66+
let rewritten = try _openExistential(macroSyntax, do: _expand)
6467
expandedSource = rewritten.description
6568

6669
case let declMacroDef as DeclarationMacro.Type:
67-
let rewritten = try declMacroDef.expansion(of: macroSyntax, in: context)
70+
func _expand<Node: FreestandingMacroExpansionSyntax>(node: Node) throws -> [DeclSyntax] {
71+
try declMacroDef.expansion(of: node, in: context)
72+
}
73+
let rewritten = try _openExistential(macroSyntax, do: _expand)
6874
expandedSource = CodeBlockItemListSyntax(rewritten.map { CodeBlockItemSyntax(item: .decl($0)) }).description
6975

7076
default:

0 commit comments

Comments
 (0)