Skip to content

Commit 82da284

Browse files
committed
fix: use attributesToRemove instead of getting attributes
1 parent fbc962f commit 82da284

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

Sources/SwiftSyntaxMacroExpansion/MacroSystem.swift

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -706,14 +706,6 @@ private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
706706
let attributedNode = node.asProtocol(WithAttributesSyntax.self),
707707
!attributedNode.attributes.isEmpty
708708
{
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-
}
717709
// Apply body and preamble macros.
718710
if let nodeWithBody = node.asProtocol(WithOptionalCodeBlockSyntax.self),
719711
let declNodeWithBody = nodeWithBody as? any DeclSyntaxProtocol & WithOptionalCodeBlockSyntax
@@ -726,9 +718,21 @@ private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
726718
let visitedNode = self.visit(declSyntax)
727719
skipVisitAnyHandling.remove(Syntax(declSyntax))
728720

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+
}
730732

731-
return AttributeRemover(removingWhere: { attributesToRemove.contains($0) }).rewrite(visitedNode)
733+
return AttributeRemover(removingWhere: { attributesToRemove.map(\.attributeNode).contains($0) }).rewrite(
734+
visitedNode
735+
)
732736
}
733737

734738
return nil
@@ -963,6 +967,12 @@ private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
963967
node.accessorBlock = expandAccessors(of: node, existingAccessors: node.accessorBlock).accessors
964968
return DeclSyntax(node)
965969
}
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+
// }
966976
}
967977

968978
// MARK: Attached macro expansions.

0 commit comments

Comments
 (0)