@@ -706,14 +706,6 @@ private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
706
706
let attributedNode = node. asProtocol ( WithAttributesSyntax . self) ,
707
707
!attributedNode. attributes. isEmpty
708
708
{
709
- if ( !macroAttributes( attachedTo: declSyntax, ofType: AccessorMacro . Type. self) . isEmpty
710
- && !declSyntax. is ( VariableDeclSyntax . self) && !declSyntax. is ( SubscriptDeclSyntax . self) )
711
- {
712
- contextGenerator ( node) . addDiagnostics (
713
- from: MacroApplicationError . accessorMacroNotOnVariableOrSubscript,
714
- node: declSyntax
715
- )
716
- }
717
709
// Apply body and preamble macros.
718
710
if let nodeWithBody = node. asProtocol ( WithOptionalCodeBlockSyntax . self) ,
719
711
let declNodeWithBody = nodeWithBody as? any DeclSyntaxProtocol & WithOptionalCodeBlockSyntax
@@ -726,9 +718,21 @@ private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
726
718
let visitedNode = self . visit ( declSyntax)
727
719
skipVisitAnyHandling. remove ( Syntax ( declSyntax) )
728
720
729
- let attributesToRemove = self . macroAttributes ( attachedTo: visitedNode) . map ( \. attributeNode)
721
+ let attributesToRemove = self . macroAttributes ( attachedTo: visitedNode)
722
+ attributesToRemove. forEach { ( attribute, spec) in
723
+ if let _ = spec. type as? AccessorMacro . Type ,
724
+ !declSyntax. is ( VariableDeclSyntax . self) && !declSyntax. is ( SubscriptDeclSyntax . self)
725
+ {
726
+ contextGenerator ( node) . addDiagnostics (
727
+ from: MacroApplicationError . accessorMacroNotOnVariableOrSubscript,
728
+ node: declSyntax
729
+ )
730
+ }
731
+ }
730
732
731
- return AttributeRemover ( removingWhere: { attributesToRemove. contains ( $0) } ) . rewrite ( visitedNode)
733
+ return AttributeRemover ( removingWhere: { attributesToRemove. map ( \. attributeNode) . contains ( $0) } ) . rewrite (
734
+ visitedNode
735
+ )
732
736
}
733
737
734
738
return nil
@@ -963,6 +967,12 @@ private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
963
967
node. accessorBlock = expandAccessors ( of: node, existingAccessors: node. accessorBlock) . accessors
964
968
return DeclSyntax ( node)
965
969
}
970
+
971
+ // override func visit(_ node: StructDeclSyntax) -> DeclSyntax {
972
+ // let node = super.visit(node).cast(StructDeclSyntax.self)
973
+ // let expansion = expandAccessors(of: node, existingAccessors: nil)
974
+ // return DeclSyntax(node)
975
+ // }
966
976
}
967
977
968
978
// MARK: Attached macro expansions.
0 commit comments