File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed
Sources/SwiftSyntaxMacroExpansion
Tests/SwiftSyntaxMacroExpansionTest Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -618,6 +618,10 @@ private class MacroApplication<Context: MacroExpansionContext>: SyntaxRewriter {
618618 }
619619
620620 override func visit( _ node: VariableDeclSyntax ) -> DeclSyntax {
621+ guard !macroAttributes( attachedTo: DeclSyntax ( node) , ofType: AccessorMacro . Type. self) . isEmpty else {
622+ return super. visit ( node) . cast ( DeclSyntax . self)
623+ }
624+
621625 var node = super. visit ( node) . cast ( VariableDeclSyntax . self)
622626 guard node. bindings. count == 1 , let binding = node. bindings. first else {
623627 context. addDiagnostics ( from: MacroApplicationError . accessorMacroOnVariableWithMultipleBindings, node: node)
Original file line number Diff line number Diff line change @@ -660,6 +660,19 @@ public struct DeclsFromStringsMacroNoAttrs: DeclarationMacro {
660660 }
661661}
662662
663+ fileprivate struct NoOpMemberMacro : MemberMacro {
664+ public static func expansion<
665+ Declaration: DeclGroupSyntax ,
666+ Context: MacroExpansionContext
667+ > (
668+ of node: AttributeSyntax ,
669+ providingMembersOf declaration: Declaration ,
670+ in context: Context
671+ ) throws -> [ DeclSyntax ] {
672+ return [ ]
673+ }
674+ }
675+
663676// MARK: Tests
664677
665678/// The set of test macros we use here.
@@ -1894,4 +1907,44 @@ final class MacroSystemTests: XCTestCase {
18941907 macros: [ " decl " : DeclMacro . self, " Peer " : MyPeerMacro . self]
18951908 )
18961909 }
1910+
1911+ func testStructVariableDeclWithMultipleBindings( ) {
1912+ assertMacroExpansion (
1913+ """
1914+ @Test
1915+ struct S {
1916+ var x: Int, y: Int
1917+ }
1918+ """ ,
1919+ expandedSource: """
1920+ struct S {
1921+ var x: Int, y: Int
1922+ }
1923+ """ ,
1924+ macros: [ " Test " : NoOpMemberMacro . self] ,
1925+ indentationWidth: indentationWidth
1926+ )
1927+ }
1928+
1929+ func testNestedStructVariableDeclWithMultipleBindings( ) {
1930+ assertMacroExpansion (
1931+ """
1932+ @Test
1933+ struct Q {
1934+ struct R {
1935+ var i: Int, j: Int
1936+ }
1937+ }
1938+ """ ,
1939+ expandedSource: """
1940+ struct Q {
1941+ struct R {
1942+ var i: Int, j: Int
1943+ }
1944+ }
1945+ """ ,
1946+ macros: [ " Test " : NoOpMemberMacro . self] ,
1947+ indentationWidth: indentationWidth
1948+ )
1949+ }
18971950}
You can’t perform that action at this time.
0 commit comments