Skip to content

Commit 44216a3

Browse files
committed
fix: temp for cr
1 parent 09252c7 commit 44216a3

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

Sources/SwiftSyntaxMacroExpansion/MacroSystem.swift

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
669669
/// Store expanded extension while visiting member decls. This should be
670670
/// added to top-level 'CodeBlockItemList'.
671671
var extensions: [CodeBlockItemSyntax] = []
672+
var expandedAttributes: [AttributeSyntax] = []
672673

673674
init(
674675
macroSystem: MacroSystem,
@@ -720,16 +721,21 @@ private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
720721

721722
let attributesToRemove = self.macroAttributes(attachedTo: visitedNode)
722723
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-
)
724+
if let index = self.expandedAttributes.firstIndex(where: { expandedAttribute in
725+
expandedAttribute.id.indexInTree == attribute.id.indexInTree
726+
}) {
727+
self.expandedAttributes.remove(at: index)
728+
} else {
729+
if let _ = spec.type as? AccessorMacro.Type,
730+
!declSyntax.is(VariableDeclSyntax.self) && !declSyntax.is(SubscriptDeclSyntax.self)
731+
{
732+
contextGenerator(node).addDiagnostics(
733+
from: MacroApplicationError.accessorMacroNotOnVariableOrSubscript,
734+
node: declSyntax
735+
)
736+
}
730737
}
731738
}
732-
733739
return AttributeRemover(removingWhere: { attributesToRemove.map(\.attributeNode).contains($0) }).rewrite(
734740
visitedNode
735741
)
@@ -1038,6 +1044,7 @@ extension MacroApplication {
10381044
macroAttribute.conformanceList
10391045
) {
10401046
result += expanded
1047+
self.expandedAttributes.append(macroAttribute.attributeNode)
10411048
}
10421049
} catch {
10431050
contextGenerator(Syntax(decl)).addDiagnostics(from: error, node: macroAttribute.attributeNode)
@@ -1185,6 +1192,7 @@ extension MacroApplication {
11851192
from: newAccessors,
11861193
indentationWidth: self.indentationWidth
11871194
)
1195+
self.expandedAttributes.append(macro.attributeNode)
11881196
}
11891197
} else if let newAccessors = try expandAccessorMacroWithoutExistingAccessors(
11901198
definition: macro.definition,
@@ -1207,11 +1215,13 @@ extension MacroApplication {
12071215
} else {
12081216
newAccessorsBlock = newAccessors
12091217
}
1218+
self.expandedAttributes.append(macro.attributeNode)
12101219
}
12111220
} catch {
12121221
contextGenerator(Syntax(storage)).addDiagnostics(from: error, node: macro.attributeNode)
12131222
}
12141223
}
1224+
12151225
return (newAccessorsBlock, expandsGetSet)
12161226
}
12171227
}

0 commit comments

Comments
 (0)