File tree 2 files changed +57
-0
lines changed
Sources/SwiftSyntaxMacroExpansion
Tests/SwiftSyntaxMacroExpansionTest
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 {
618
618
}
619
619
620
620
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
+
621
625
var node = super. visit ( node) . cast ( VariableDeclSyntax . self)
622
626
guard node. bindings. count == 1 , let binding = node. bindings. first else {
623
627
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 {
660
660
}
661
661
}
662
662
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
+
663
676
// MARK: Tests
664
677
665
678
/// The set of test macros we use here.
@@ -1894,4 +1907,44 @@ final class MacroSystemTests: XCTestCase {
1894
1907
macros: [ " decl " : DeclMacro . self, " Peer " : MyPeerMacro . self]
1895
1908
)
1896
1909
}
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
+ }
1897
1950
}
You can’t perform that action at this time.
0 commit comments