@@ -1281,14 +1281,16 @@ public struct EmptyPeerMacro: PeerMacro {
12811281 }
12821282}
12831283
1284- public struct EquatableMacro : ConformanceMacro {
1284+ public struct EquatableMacro : ExtensionMacro {
12851285 public static func expansion(
12861286 of node: AttributeSyntax ,
1287- providingConformancesOf decl: some DeclGroupSyntax ,
1287+ attachedTo: some DeclGroupSyntax ,
1288+ providingExtensionsOf type: some TypeSyntaxProtocol ,
1289+ conformingTo protocols: [ TypeSyntax ] ,
12881290 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 ) ]
12921294 }
12931295}
12941296
@@ -1316,34 +1318,37 @@ public struct ConformanceViaExtensionMacro: ExtensionMacro {
13161318 }
13171319}
13181320
1319- public struct HashableMacro : ConformanceMacro {
1321+ public struct HashableMacro : ExtensionMacro {
13201322 public static func expansion(
13211323 of node: AttributeSyntax ,
1322- providingConformancesOf decl: some DeclGroupSyntax ,
1324+ attachedTo: some DeclGroupSyntax ,
1325+ providingExtensionsOf type: some TypeSyntaxProtocol ,
1326+ conformingTo protocols: [ TypeSyntax ] ,
13231327 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 ) ]
13271331 }
13281332}
13291333
1330- public struct DelegatedConformanceMacro : ConformanceMacro , MemberMacro {
1334+ public struct DelegatedConformanceMacro : ExtensionMacro , MemberMacro {
13311335 public static func expansion(
13321336 of node: AttributeSyntax ,
1333- providingConformancesOf decl: some DeclGroupSyntax ,
1337+ attachedTo: some DeclGroupSyntax ,
1338+ providingExtensionsOf type: some TypeSyntaxProtocol ,
1339+ conformingTo protocols: [ TypeSyntax ] ,
13341340 in context: some MacroExpansionContext
1335- ) throws -> [ ( TypeSyntax , GenericWhereClauseSyntax ? ) ] {
1336- let protocolName : TypeSyntax = " P "
1341+ ) throws -> [ ExtensionDeclSyntax ] {
13371342 let conformance : DeclSyntax =
13381343 """
1339- extension Placeholder where Element: P {}
1344+ extension \( type . trimmed ) : P where Element: P {}
13401345 """
13411346
13421347 guard let extensionDecl = conformance. as ( ExtensionDeclSyntax . self) else {
13431348 return [ ]
13441349 }
13451350
1346- return [ ( protocolName , extensionDecl. genericWhereClause ) ]
1351+ return [ extensionDecl]
13471352 }
13481353
13491354 public static func expansion(
@@ -1760,26 +1765,21 @@ public struct AddPeerStoredPropertyMacro: PeerMacro, Sendable {
17601765 }
17611766}
17621767
1763- public struct InitializableMacro : ConformanceMacro , MemberMacro {
1768+ public struct InitializableMacro : ExtensionMacro {
17641769 public static func expansion(
17651770 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 ] ,
17751774 in context: some MacroExpansionContext
1776- ) throws -> [ DeclSyntax ] {
1777- let requirement : DeclSyntax =
1775+ ) throws -> [ ExtensionDeclSyntax ] {
1776+ let ext : DeclSyntax =
17781777 """
1779- init(value: Int) {}
1778+ extension \( type. trimmed) : Initializable {
1779+ init(value: Int) {}
1780+ }
17801781 """
1781-
1782- return [ requirement]
1782+ return [ ext. cast ( ExtensionDeclSyntax . self) ]
17831783 }
17841784}
17851785
0 commit comments