@@ -1344,14 +1344,16 @@ public struct EmptyPeerMacro: PeerMacro {
1344
1344
}
1345
1345
}
1346
1346
1347
- public struct EquatableMacro : ConformanceMacro {
1347
+ public struct EquatableMacro : ExtensionMacro {
1348
1348
public static func expansion(
1349
1349
of node: AttributeSyntax ,
1350
- providingConformancesOf decl: some DeclGroupSyntax ,
1350
+ attachedTo: some DeclGroupSyntax ,
1351
+ providingExtensionsOf type: some TypeSyntaxProtocol ,
1352
+ conformingTo protocols: [ TypeSyntax ] ,
1351
1353
in context: some MacroExpansionContext
1352
- ) throws -> [ ( TypeSyntax , GenericWhereClauseSyntax ? ) ] {
1353
- let protocolName : TypeSyntax = " Equatable "
1354
- return [ ( protocolName , nil ) ]
1354
+ ) throws -> [ ExtensionDeclSyntax ] {
1355
+ let ext : DeclSyntax = " extension \( type . trimmed ) : Equatable {} "
1356
+ return [ ext . cast ( ExtensionDeclSyntax . self ) ]
1355
1357
}
1356
1358
}
1357
1359
@@ -1412,34 +1414,37 @@ public struct ConformanceViaExtensionMacro: ExtensionMacro {
1412
1414
}
1413
1415
}
1414
1416
1415
- public struct HashableMacro : ConformanceMacro {
1417
+ public struct HashableMacro : ExtensionMacro {
1416
1418
public static func expansion(
1417
1419
of node: AttributeSyntax ,
1418
- providingConformancesOf decl: some DeclGroupSyntax ,
1420
+ attachedTo: some DeclGroupSyntax ,
1421
+ providingExtensionsOf type: some TypeSyntaxProtocol ,
1422
+ conformingTo protocols: [ TypeSyntax ] ,
1419
1423
in context: some MacroExpansionContext
1420
- ) throws -> [ ( TypeSyntax , GenericWhereClauseSyntax ? ) ] {
1421
- let protocolName : TypeSyntax = " Hashable "
1422
- return [ ( protocolName , nil ) ]
1424
+ ) throws -> [ ExtensionDeclSyntax ] {
1425
+ let ext : DeclSyntax = " extension \( type . trimmed ) : Hashable {} "
1426
+ return [ ext . cast ( ExtensionDeclSyntax . self ) ]
1423
1427
}
1424
1428
}
1425
1429
1426
- public struct DelegatedConformanceMacro : ConformanceMacro , MemberMacro {
1430
+ public struct DelegatedConformanceMacro : ExtensionMacro , MemberMacro {
1427
1431
public static func expansion(
1428
1432
of node: AttributeSyntax ,
1429
- providingConformancesOf decl: some DeclGroupSyntax ,
1433
+ attachedTo: some DeclGroupSyntax ,
1434
+ providingExtensionsOf type: some TypeSyntaxProtocol ,
1435
+ conformingTo protocols: [ TypeSyntax ] ,
1430
1436
in context: some MacroExpansionContext
1431
- ) throws -> [ ( TypeSyntax , GenericWhereClauseSyntax ? ) ] {
1432
- let protocolName : TypeSyntax = " P "
1437
+ ) throws -> [ ExtensionDeclSyntax ] {
1433
1438
let conformance : DeclSyntax =
1434
1439
"""
1435
- extension Placeholder where Element: P {}
1440
+ extension \( type . trimmed ) : P where Element: P {}
1436
1441
"""
1437
1442
1438
1443
guard let extensionDecl = conformance. as ( ExtensionDeclSyntax . self) else {
1439
1444
return [ ]
1440
1445
}
1441
1446
1442
- return [ ( protocolName , extensionDecl. genericWhereClause ) ]
1447
+ return [ extensionDecl]
1443
1448
}
1444
1449
1445
1450
public static func expansion(
@@ -1894,26 +1899,21 @@ public struct AddPeerStoredPropertyMacro: PeerMacro, Sendable {
1894
1899
}
1895
1900
}
1896
1901
1897
- public struct InitializableMacro : ConformanceMacro , MemberMacro {
1898
- public static func expansion(
1899
- of node: AttributeSyntax ,
1900
- providingConformancesOf decl: some DeclGroupSyntax ,
1901
- in context: some MacroExpansionContext
1902
- ) throws -> [ ( TypeSyntax , GenericWhereClauseSyntax ? ) ] {
1903
- return [ ( " Initializable " , nil ) ]
1904
- }
1905
-
1902
+ public struct InitializableMacro : ExtensionMacro {
1906
1903
public static func expansion(
1907
1904
of node: AttributeSyntax ,
1908
- providingMembersOf decl: some DeclGroupSyntax ,
1905
+ attachedTo: some DeclGroupSyntax ,
1906
+ providingExtensionsOf type: some TypeSyntaxProtocol ,
1907
+ conformingTo protocols: [ TypeSyntax ] ,
1909
1908
in context: some MacroExpansionContext
1910
- ) throws -> [ DeclSyntax ] {
1911
- let requirement : DeclSyntax =
1909
+ ) throws -> [ ExtensionDeclSyntax ] {
1910
+ let ext : DeclSyntax =
1912
1911
"""
1913
- init(value: Int) {}
1912
+ extension \( type. trimmed) : Initializable {
1913
+ init(value: Int) {}
1914
+ }
1914
1915
"""
1915
-
1916
- return [ requirement]
1916
+ return [ ext. cast ( ExtensionDeclSyntax . self) ]
1917
1917
}
1918
1918
}
1919
1919
0 commit comments