Skip to content

Commit 5d79729

Browse files
authored
Merge pull request #1377 from rintaro/pluing-freestanding-openexistential
[CompilerPlugin/Macros] Pass macro syntax using _openExistential
2 parents 94b9021 + 1ea916e commit 5d79729

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)