Skip to content

Commit 8efc674

Browse files
committed
Generize MemberMacro protocol
1 parent b9ef035 commit 8efc674

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

Sources/_SwiftSyntaxMacros/MacroProtocols/MemberMacro.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ 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-
static func expansion(
26+
static func expansion<
27+
Declaration: DeclGroupSyntax,
28+
Context: MacroExpansionContext
29+
>(
2730
of node: AttributeSyntax,
28-
attachedTo declaration: DeclSyntax,
29-
in context: any MacroExpansionContext
31+
attachedTo declaration: Declaration,
32+
in context: Context
3033
) throws -> [DeclSyntax]
3134
}
3235

Sources/_SwiftSyntaxMacros/MacroSystem.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ extension MacroApplication {
401401
try newMembers.append(
402402
contentsOf: memberMacro.expansion(
403403
of: attribute,
404-
attachedTo: DeclSyntax(decl),
404+
attachedTo: decl,
405405
in: context
406406
)
407407
)
@@ -495,9 +495,9 @@ extension MacroApplication {
495495
extension SyntaxProtocol {
496496
/// Expand all uses of the given set of macros within this syntax
497497
/// node.
498-
public func expand(
498+
public func expand<Context: MacroExpansionContext>(
499499
macros: [String: Macro.Type],
500-
in context: any MacroExpansionContext
500+
in context: Context
501501
) -> Syntax {
502502
// Build the macro system.
503503
var system = MacroSystem()

Tests/SwiftSyntaxMacrosTest/MacroSystemTests.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,13 @@ public struct AddCompletionHandler: PeerMacro {
440440
}
441441

442442
public struct AddBackingStorage: MemberMacro {
443-
public static func expansion(
443+
public static func expansion<
444+
Declaration: DeclGroupSyntax,
445+
Context: MacroExpansionContext
446+
>(
444447
of node: AttributeSyntax,
445-
attachedTo decl: DeclSyntax,
446-
in context: any MacroExpansionContext
448+
attachedTo decl: Declaration,
449+
in context: Context
447450
)
448451
throws -> [DeclSyntax]
449452
{
@@ -527,10 +530,13 @@ public struct WrapStoredProperties: MemberAttributeMacro {
527530
struct CustomTypeWrapperMacro {}
528531

529532
extension CustomTypeWrapperMacro: MemberMacro {
530-
static func expansion(
533+
static func expansion<
534+
Declaration: DeclGroupSyntax,
535+
Context: MacroExpansionContext
536+
>(
531537
of node: AttributeSyntax,
532-
attachedTo declaration: DeclSyntax,
533-
in context: any MacroExpansionContext
538+
attachedTo declaration: Declaration,
539+
in context: Context
534540
) throws -> [DeclSyntax] {
535541
return [
536542
"""

0 commit comments

Comments
 (0)