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(
583
583
return 1
584
584
}
585
585
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 (
590
588
sourceFilePtr: declarationSourceFilePtr,
591
589
sourceLocationPtr: declarationSourceLocPointer,
592
- type: Syntax . self
590
+ type: T . self
593
591
)
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 {
595
602
return 1
596
603
}
597
604
@@ -622,7 +629,7 @@ func expandAttachedMacro(
622
629
customAttrSourceFilePtr: customAttrSourceFilePtr,
623
630
customAttrNode: customAttrNode,
624
631
declarationSourceFilePtr: declarationSourceFilePtr,
625
- attachedTo: declarationNode ,
632
+ attachedTo: node ,
626
633
parentDeclSourceFilePtr: parentDeclSourceFilePtr,
627
634
parentDeclNode: parentDeclNode
628
635
)
You can’t perform that action at this time.
0 commit comments