Skip to content

Commit 8d1c176

Browse files
committed
Allow either requirement of MemberMacro to be implemented
... and try again for the name of the new method, using "preexistingConformances" instead of "missingConformancesTo".
1 parent 6ff4a07 commit 8d1c176

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Sources/SwiftSyntaxMacroExpansion/MacroExpansion.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public func expandAttachedMacroWithoutCollapsing<Context: MacroExpansionContext>
236236
let members = try attachedMacro.expansion(
237237
of: attributeNode,
238238
providingMembersOf: declGroup,
239-
missingConformancesTo: conformanceList?.map(\.type) ?? [],
239+
implementingRequirementsFor: conformanceList?.map(\.type) ?? [],
240240
in: context
241241
)
242242

Sources/SwiftSyntaxMacros/MacroProtocols/MemberMacro.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public protocol MemberMacro: AttachedMacro {
2323
///
2424
/// - Returns: the set of member declarations introduced by this macro, which
2525
/// are nested inside the `attachedTo` declaration.
26+
@available(*, deprecated, message: "Use expansion(of:providingMembersOf:implementingRequirementsFor:in:")
2627
static func expansion(
2728
of node: AttributeSyntax,
2829
providingMembersOf declaration: some DeclGroupSyntax,
@@ -34,7 +35,7 @@ public protocol MemberMacro: AttachedMacro {
3435
/// - Parameters:
3536
/// - node: The custom attribute describing the attached macro.
3637
/// - declaration: The declaration the macro attribute is attached to.
37-
/// - missingConformancesTo: The set of protocols that were declared
38+
/// - implementingRequirementsFor: The set of protocols that were declared
3839
/// in the set of conformances for the macro and to which the declaration
3940
/// does not explicitly conform. The member macro itself cannot declare
4041
/// conformances to these protocols (only an extension macro can do that),
@@ -48,17 +49,26 @@ public protocol MemberMacro: AttachedMacro {
4849
static func expansion(
4950
of node: AttributeSyntax,
5051
providingMembersOf declaration: some DeclGroupSyntax,
51-
missingConformancesTo protocols: [TypeSyntax],
52+
implementingRequirementsFor protocols: [TypeSyntax],
5253
in context: some MacroExpansionContext
5354
) throws -> [DeclSyntax]
5455
}
5556

5657
public extension MemberMacro {
58+
/// Default implementation supplies no conformances.
59+
static func expansion(
60+
of node: AttributeSyntax,
61+
providingMembersOf declaration: some DeclGroupSyntax,
62+
in context: some MacroExpansionContext
63+
) throws -> [DeclSyntax] {
64+
return try expansion(of: node, providingMembersOf: declaration, implementingRequirementsFor: [], in: context)
65+
}
66+
5767
/// Default implementation that ignores the unhandled conformances.
5868
static func expansion(
5969
of node: AttributeSyntax,
6070
providingMembersOf declaration: some DeclGroupSyntax,
61-
missingConformancesTo protocols: [TypeSyntax],
71+
implementingRequirementsFor protocols: [TypeSyntax],
6272
in context: some MacroExpansionContext
6373
) throws -> [DeclSyntax] {
6474
return try expansion(of: node, providingMembersOf: declaration, in: context)

0 commit comments

Comments
 (0)