Skip to content

Commit 9b93576

Browse files
committed
Adjust to swift-syntax parsing freestanding macros as declarations more often
1 parent d74f235 commit 9b93576

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/ASTGen/Sources/ASTGen/Macros.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,16 @@ func evaluateMacro(
169169
switch macroPtr.pointee.macro {
170170
// Handle expression macro.
171171
case let exprMacro as ExpressionMacro.Type:
172-
guard let parentExpansion = parentSyntax.as(MacroExpansionExprSyntax.self) else {
173-
print("not on a macro expansion node: \(token.recursiveDescription)")
172+
let parentExpansion: MacroExpansionExprSyntax
173+
if let expansionExpr = parentSyntax.as(MacroExpansionExprSyntax.self) {
174+
parentExpansion = expansionExpr
175+
} else if let expansionDecl = parentSyntax.as(MacroExpansionDeclSyntax.self) {
176+
parentExpansion = expansionDecl.asMacroExpansionExpr()
177+
} else {
178+
print("not on a macro expansion node: \(parentSyntax.recursiveDescription)")
174179
return -1
175180
}
181+
176182
macroName = parentExpansion.macro.withoutTrivia().description
177183
evaluatedSyntax = Syntax(try exprMacro.expansion(of: parentExpansion, in: &context))
178184

0 commit comments

Comments
 (0)