File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed
lib/ASTGen/Sources/MacroEvaluation Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -583,15 +583,22 @@ func expandAttachedMacro(
583583 return 1
584584 }
585585
586- // Dig out the node for the declaration to which the custom attribute is
587- // attached.
588- guard
589- let declarationNode = findSyntaxNodeInSourceFile (
586+ func findNode< T: SyntaxProtocol > ( type: T . Type ) -> T ? {
587+ findSyntaxNodeInSourceFile (
590588 sourceFilePtr: declarationSourceFilePtr,
591589 sourceLocationPtr: declarationSourceLocPointer,
592- type: Syntax . self
590+ type: T . self
593591 )
594- else {
592+ }
593+
594+ // Dig out the node for the closure or declaration to which the custom
595+ // attribute is attached.
596+ let node : Syntax
597+ if let closureNode = findNode ( type: ClosureExprSyntax . self) {
598+ node = Syntax ( closureNode)
599+ } else if let declNode = findNode ( type: DeclSyntax . self) {
600+ node = Syntax ( declNode)
601+ } else {
595602 return 1
596603 }
597604
@@ -622,7 +629,7 @@ func expandAttachedMacro(
622629 customAttrSourceFilePtr: customAttrSourceFilePtr,
623630 customAttrNode: customAttrNode,
624631 declarationSourceFilePtr: declarationSourceFilePtr,
625- attachedTo: declarationNode ,
632+ attachedTo: node ,
626633 parentDeclSourceFilePtr: parentDeclSourceFilePtr,
627634 parentDeclNode: parentDeclNode
628635 )
You can’t perform that action at this time.
0 commit comments