Skip to content

Commit 2dc73b9

Browse files
committed
Genericize AccessorMacro
The bounds aren't quite what I was hoping for, because we don't have a way to abstract over "nodes that have accessors".
1 parent a3171a4 commit 2dc73b9

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

Sources/_SwiftSyntaxMacros/MacroProtocols/AccessorMacro.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ public protocol AccessorMacro: AttachedMacro {
1414
/// Expand a macro that's expressed as a custom attribute attached to
1515
/// the given declaration. The result is a set of accessors for the
1616
/// declaration.
17-
static func expansion(
17+
static func expansion<
18+
Context: MacroExpansionContext,
19+
Declaration: DeclSyntaxProtocol
20+
>(
1821
of node: AttributeSyntax,
19-
attachedTo declaration: DeclSyntax,
20-
in context: any MacroExpansionContext
22+
attachedTo declaration: Declaration,
23+
in context: Context
2124
) throws -> [AccessorDeclSyntax]
2225
}
2326

Tests/SwiftSyntaxMacrosTest/MacroSystemTests.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,13 @@ struct DefineBitwidthNumberedStructsMacro: DeclarationMacro {
254254
public struct PropertyWrapper {}
255255

256256
extension PropertyWrapper: AccessorMacro {
257-
public static func expansion(
257+
public static func expansion<
258+
Context: MacroExpansionContext,
259+
Declaration: DeclSyntaxProtocol
260+
>(
258261
of node: AttributeSyntax,
259-
attachedTo declaration: DeclSyntax,
260-
in context: any MacroExpansionContext
262+
attachedTo declaration: Declaration,
263+
in context: Context
261264
) throws -> [AccessorDeclSyntax] {
262265
guard let varDecl = declaration.as(VariableDeclSyntax.self),
263266
let binding = varDecl.bindings.first,
@@ -569,10 +572,13 @@ extension CustomTypeWrapperMacro: MemberAttributeMacro {
569572
}
570573

571574
extension CustomTypeWrapperMacro: AccessorMacro {
572-
static func expansion(
575+
static func expansion<
576+
Context: MacroExpansionContext,
577+
Declaration: DeclSyntaxProtocol
578+
>(
573579
of node: AttributeSyntax,
574-
attachedTo declaration: DeclSyntax,
575-
in context: any MacroExpansionContext
580+
attachedTo declaration: Declaration,
581+
in context: Context
576582
) throws -> [AccessorDeclSyntax] {
577583
guard let property = declaration.as(VariableDeclSyntax.self),
578584
let binding = property.bindings.first,

0 commit comments

Comments
 (0)