@@ -1324,14 +1324,16 @@ public struct EmptyPeerMacro: PeerMacro {
1324
1324
}
1325
1325
}
1326
1326
1327
- public struct EquatableMacro : ConformanceMacro {
1327
+ public struct EquatableMacro : ExtensionMacro {
1328
1328
public static func expansion(
1329
1329
of node: AttributeSyntax ,
1330
- providingConformancesOf decl: some DeclGroupSyntax ,
1330
+ attachedTo: some DeclGroupSyntax ,
1331
+ providingExtensionsOf type: some TypeSyntaxProtocol ,
1332
+ conformingTo protocols: [ TypeSyntax ] ,
1331
1333
in context: some MacroExpansionContext
1332
- ) throws -> [ ( TypeSyntax , GenericWhereClauseSyntax ? ) ] {
1333
- let protocolName : TypeSyntax = " Equatable "
1334
- return [ ( protocolName , nil ) ]
1334
+ ) throws -> [ ExtensionDeclSyntax ] {
1335
+ let ext : DeclSyntax = " extension \( type . trimmed ) : Equatable {} "
1336
+ return [ ext . cast ( ExtensionDeclSyntax . self ) ]
1335
1337
}
1336
1338
}
1337
1339
@@ -1359,34 +1361,37 @@ public struct ConformanceViaExtensionMacro: ExtensionMacro {
1359
1361
}
1360
1362
}
1361
1363
1362
- public struct HashableMacro : ConformanceMacro {
1364
+ public struct HashableMacro : ExtensionMacro {
1363
1365
public static func expansion(
1364
1366
of node: AttributeSyntax ,
1365
- providingConformancesOf decl: some DeclGroupSyntax ,
1367
+ attachedTo: some DeclGroupSyntax ,
1368
+ providingExtensionsOf type: some TypeSyntaxProtocol ,
1369
+ conformingTo protocols: [ TypeSyntax ] ,
1366
1370
in context: some MacroExpansionContext
1367
- ) throws -> [ ( TypeSyntax , GenericWhereClauseSyntax ? ) ] {
1368
- let protocolName : TypeSyntax = " Hashable "
1369
- return [ ( protocolName , nil ) ]
1371
+ ) throws -> [ ExtensionDeclSyntax ] {
1372
+ let ext : DeclSyntax = " extension \( type . trimmed ) : Hashable {} "
1373
+ return [ ext . cast ( ExtensionDeclSyntax . self ) ]
1370
1374
}
1371
1375
}
1372
1376
1373
- public struct DelegatedConformanceMacro : ConformanceMacro , MemberMacro {
1377
+ public struct DelegatedConformanceMacro : ExtensionMacro , MemberMacro {
1374
1378
public static func expansion(
1375
1379
of node: AttributeSyntax ,
1376
- providingConformancesOf decl: some DeclGroupSyntax ,
1380
+ attachedTo: some DeclGroupSyntax ,
1381
+ providingExtensionsOf type: some TypeSyntaxProtocol ,
1382
+ conformingTo protocols: [ TypeSyntax ] ,
1377
1383
in context: some MacroExpansionContext
1378
- ) throws -> [ ( TypeSyntax , GenericWhereClauseSyntax ? ) ] {
1379
- let protocolName : TypeSyntax = " P "
1384
+ ) throws -> [ ExtensionDeclSyntax ] {
1380
1385
let conformance : DeclSyntax =
1381
1386
"""
1382
- extension Placeholder where Element: P {}
1387
+ extension \( type . trimmed ) : P where Element: P {}
1383
1388
"""
1384
1389
1385
1390
guard let extensionDecl = conformance. as ( ExtensionDeclSyntax . self) else {
1386
1391
return [ ]
1387
1392
}
1388
1393
1389
- return [ ( protocolName , extensionDecl. genericWhereClause ) ]
1394
+ return [ extensionDecl]
1390
1395
}
1391
1396
1392
1397
public static func expansion(
@@ -1803,26 +1808,21 @@ public struct AddPeerStoredPropertyMacro: PeerMacro, Sendable {
1803
1808
}
1804
1809
}
1805
1810
1806
- public struct InitializableMacro : ConformanceMacro , MemberMacro {
1811
+ public struct InitializableMacro : ExtensionMacro {
1807
1812
public static func expansion(
1808
1813
of node: AttributeSyntax ,
1809
- providingConformancesOf decl: some DeclGroupSyntax ,
1810
- in context: some MacroExpansionContext
1811
- ) throws -> [ ( TypeSyntax , GenericWhereClauseSyntax ? ) ] {
1812
- return [ ( " Initializable " , nil ) ]
1813
- }
1814
-
1815
- public static func expansion(
1816
- of node: AttributeSyntax ,
1817
- providingMembersOf decl: some DeclGroupSyntax ,
1814
+ attachedTo: some DeclGroupSyntax ,
1815
+ providingExtensionsOf type: some TypeSyntaxProtocol ,
1816
+ conformingTo protocols: [ TypeSyntax ] ,
1818
1817
in context: some MacroExpansionContext
1819
- ) throws -> [ DeclSyntax ] {
1820
- let requirement : DeclSyntax =
1818
+ ) throws -> [ ExtensionDeclSyntax ] {
1819
+ let ext : DeclSyntax =
1821
1820
"""
1822
- init(value: Int) {}
1821
+ extension \( type. trimmed) : Initializable {
1822
+ init(value: Int) {}
1823
+ }
1823
1824
"""
1824
-
1825
- return [ requirement]
1825
+ return [ ext. cast ( ExtensionDeclSyntax . self) ]
1826
1826
}
1827
1827
}
1828
1828
0 commit comments