Skip to content

Commit

Permalink
fix: temp for cr
Browse files Browse the repository at this point in the history
  • Loading branch information
RayZhao1998 committed Apr 27, 2024
1 parent 09252c7 commit 44216a3
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions Sources/SwiftSyntaxMacroExpansion/MacroSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
/// Store expanded extension while visiting member decls. This should be
/// added to top-level 'CodeBlockItemList'.
var extensions: [CodeBlockItemSyntax] = []
var expandedAttributes: [AttributeSyntax] = []

init(
macroSystem: MacroSystem,
Expand Down Expand Up @@ -720,16 +721,21 @@ private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {

let attributesToRemove = self.macroAttributes(attachedTo: visitedNode)
attributesToRemove.forEach { (attribute, spec) in
if let _ = spec.type as? AccessorMacro.Type,
!declSyntax.is(VariableDeclSyntax.self) && !declSyntax.is(SubscriptDeclSyntax.self)
{
contextGenerator(node).addDiagnostics(
from: MacroApplicationError.accessorMacroNotOnVariableOrSubscript,
node: declSyntax
)
if let index = self.expandedAttributes.firstIndex(where: { expandedAttribute in
expandedAttribute.id.indexInTree == attribute.id.indexInTree
}) {
self.expandedAttributes.remove(at: index)
} else {
if let _ = spec.type as? AccessorMacro.Type,
!declSyntax.is(VariableDeclSyntax.self) && !declSyntax.is(SubscriptDeclSyntax.self)
{
contextGenerator(node).addDiagnostics(
from: MacroApplicationError.accessorMacroNotOnVariableOrSubscript,
node: declSyntax
)
}
}
}

return AttributeRemover(removingWhere: { attributesToRemove.map(\.attributeNode).contains($0) }).rewrite(
visitedNode
)
Expand Down Expand Up @@ -1038,6 +1044,7 @@ extension MacroApplication {
macroAttribute.conformanceList
) {
result += expanded
self.expandedAttributes.append(macroAttribute.attributeNode)
}
} catch {
contextGenerator(Syntax(decl)).addDiagnostics(from: error, node: macroAttribute.attributeNode)
Expand Down Expand Up @@ -1185,6 +1192,7 @@ extension MacroApplication {
from: newAccessors,
indentationWidth: self.indentationWidth
)
self.expandedAttributes.append(macro.attributeNode)
}
} else if let newAccessors = try expandAccessorMacroWithoutExistingAccessors(
definition: macro.definition,
Expand All @@ -1207,11 +1215,13 @@ extension MacroApplication {
} else {
newAccessorsBlock = newAccessors
}
self.expandedAttributes.append(macro.attributeNode)
}
} catch {
contextGenerator(Syntax(storage)).addDiagnostics(from: error, node: macro.attributeNode)
}
}

return (newAccessorsBlock, expandsGetSet)
}
}
Expand Down

0 comments on commit 44216a3

Please sign in to comment.