File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -1603,3 +1603,26 @@ extension SelfAlwaysEqualOperator: MemberMacro {
1603
1603
]
1604
1604
}
1605
1605
}
1606
+
1607
+ public struct InitializableMacro : ConformanceMacro , MemberMacro {
1608
+ public static func expansion(
1609
+ of node: AttributeSyntax ,
1610
+ providingConformancesOf decl: some DeclGroupSyntax ,
1611
+ in context: some MacroExpansionContext
1612
+ ) throws -> [ ( TypeSyntax , GenericWhereClauseSyntax ? ) ] {
1613
+ return [ ( " Initializable " , nil ) ]
1614
+ }
1615
+
1616
+ public static func expansion(
1617
+ of node: AttributeSyntax ,
1618
+ providingMembersOf decl: some DeclGroupSyntax ,
1619
+ in context: some MacroExpansionContext
1620
+ ) throws -> [ DeclSyntax ] {
1621
+ let requirement : DeclSyntax =
1622
+ """
1623
+ init(value: Int) {}
1624
+ """
1625
+
1626
+ return [ requirement]
1627
+ }
1628
+ }
Original file line number Diff line number Diff line change @@ -104,3 +104,24 @@ func testGlobalVariable() {
104
104
}
105
105
106
106
#endif
107
+
108
+
109
+ @freestanding ( declaration)
110
+ macro Empty< T> ( _ closure: ( ) -> T ) = #externalMacro( module: " MacroDefinition " , type: " EmptyDeclarationMacro " )
111
+
112
+ #Empty {
113
+ S ( a: 10 , b: 10 )
114
+ }
115
+
116
+ @attached ( conformance)
117
+ @attached ( member, names: named ( init) )
118
+ macro Initializable( ) = #externalMacro( module: " MacroDefinition " , type: " InitializableMacro " )
119
+
120
+ protocol Initializable {
121
+ init ( value: Int )
122
+ }
123
+
124
+ @Initializable
125
+ struct S {
126
+ init ( a: Int , b: Int ) { }
127
+ }
You can’t perform that action at this time.
0 commit comments