@@ -1281,14 +1281,16 @@ public struct EmptyPeerMacro: PeerMacro {
1281
1281
}
1282
1282
}
1283
1283
1284
- public struct EquatableMacro : ConformanceMacro {
1284
+ public struct EquatableMacro : ExtensionMacro {
1285
1285
public static func expansion(
1286
1286
of node: AttributeSyntax ,
1287
- providingConformancesOf decl: some DeclGroupSyntax ,
1287
+ attachedTo: some DeclGroupSyntax ,
1288
+ providingExtensionsOf type: some TypeSyntaxProtocol ,
1289
+ conformingTo protocols: [ TypeSyntax ] ,
1288
1290
in context: some MacroExpansionContext
1289
- ) throws -> [ ( TypeSyntax , GenericWhereClauseSyntax ? ) ] {
1290
- let protocolName : TypeSyntax = " Equatable "
1291
- return [ ( protocolName , nil ) ]
1291
+ ) throws -> [ ExtensionDeclSyntax ] {
1292
+ let ext : DeclSyntax = " extension \( type . trimmed ) : Equatable {} "
1293
+ return [ ext . cast ( ExtensionDeclSyntax . self ) ]
1292
1294
}
1293
1295
}
1294
1296
@@ -1316,34 +1318,37 @@ public struct ConformanceViaExtensionMacro: ExtensionMacro {
1316
1318
}
1317
1319
}
1318
1320
1319
- public struct HashableMacro : ConformanceMacro {
1321
+ public struct HashableMacro : ExtensionMacro {
1320
1322
public static func expansion(
1321
1323
of node: AttributeSyntax ,
1322
- providingConformancesOf decl: some DeclGroupSyntax ,
1324
+ attachedTo: some DeclGroupSyntax ,
1325
+ providingExtensionsOf type: some TypeSyntaxProtocol ,
1326
+ conformingTo protocols: [ TypeSyntax ] ,
1323
1327
in context: some MacroExpansionContext
1324
- ) throws -> [ ( TypeSyntax , GenericWhereClauseSyntax ? ) ] {
1325
- let protocolName : TypeSyntax = " Hashable "
1326
- return [ ( protocolName , nil ) ]
1328
+ ) throws -> [ ExtensionDeclSyntax ] {
1329
+ let ext : DeclSyntax = " extension \( type . trimmed ) : Hashable {} "
1330
+ return [ ext . cast ( ExtensionDeclSyntax . self ) ]
1327
1331
}
1328
1332
}
1329
1333
1330
- public struct DelegatedConformanceMacro : ConformanceMacro , MemberMacro {
1334
+ public struct DelegatedConformanceMacro : ExtensionMacro , MemberMacro {
1331
1335
public static func expansion(
1332
1336
of node: AttributeSyntax ,
1333
- providingConformancesOf decl: some DeclGroupSyntax ,
1337
+ attachedTo: some DeclGroupSyntax ,
1338
+ providingExtensionsOf type: some TypeSyntaxProtocol ,
1339
+ conformingTo protocols: [ TypeSyntax ] ,
1334
1340
in context: some MacroExpansionContext
1335
- ) throws -> [ ( TypeSyntax , GenericWhereClauseSyntax ? ) ] {
1336
- let protocolName : TypeSyntax = " P "
1341
+ ) throws -> [ ExtensionDeclSyntax ] {
1337
1342
let conformance : DeclSyntax =
1338
1343
"""
1339
- extension Placeholder where Element: P {}
1344
+ extension \( type . trimmed ) : P where Element: P {}
1340
1345
"""
1341
1346
1342
1347
guard let extensionDecl = conformance. as ( ExtensionDeclSyntax . self) else {
1343
1348
return [ ]
1344
1349
}
1345
1350
1346
- return [ ( protocolName , extensionDecl. genericWhereClause ) ]
1351
+ return [ extensionDecl]
1347
1352
}
1348
1353
1349
1354
public static func expansion(
@@ -1760,26 +1765,21 @@ public struct AddPeerStoredPropertyMacro: PeerMacro, Sendable {
1760
1765
}
1761
1766
}
1762
1767
1763
- public struct InitializableMacro : ConformanceMacro , MemberMacro {
1768
+ public struct InitializableMacro : ExtensionMacro {
1764
1769
public static func expansion(
1765
1770
of node: AttributeSyntax ,
1766
- providingConformancesOf decl: some DeclGroupSyntax ,
1767
- in context: some MacroExpansionContext
1768
- ) throws -> [ ( TypeSyntax , GenericWhereClauseSyntax ? ) ] {
1769
- return [ ( " Initializable " , nil ) ]
1770
- }
1771
-
1772
- public static func expansion(
1773
- of node: AttributeSyntax ,
1774
- providingMembersOf decl: some DeclGroupSyntax ,
1771
+ attachedTo: some DeclGroupSyntax ,
1772
+ providingExtensionsOf type: some TypeSyntaxProtocol ,
1773
+ conformingTo protocols: [ TypeSyntax ] ,
1775
1774
in context: some MacroExpansionContext
1776
- ) throws -> [ DeclSyntax ] {
1777
- let requirement : DeclSyntax =
1775
+ ) throws -> [ ExtensionDeclSyntax ] {
1776
+ let ext : DeclSyntax =
1778
1777
"""
1779
- init(value: Int) {}
1778
+ extension \( type. trimmed) : Initializable {
1779
+ init(value: Int) {}
1780
+ }
1780
1781
"""
1781
-
1782
- return [ requirement]
1782
+ return [ ext. cast ( ExtensionDeclSyntax . self) ]
1783
1783
}
1784
1784
}
1785
1785
0 commit comments