Skip to content

Commit b8ce4f6

Browse files
authored
Merge pull request #1317 from hborla/peer-macro-type-parameter
[Macros] Use a type parameter conforming to DeclSyntaxProtocol in the PeerMacro protocol requirement.
2 parents 4c9c719 + 8030e78 commit b8ce4f6

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

Sources/SwiftSyntaxMacros/MacroProtocols/PeerMacro.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ public protocol PeerMacro: AttachedMacro {
1616
///
1717
/// The macro expansion can introduce "peer" declarations that sit alongside
1818
/// the given declaration.
19-
static func expansion<Context: MacroExpansionContext>(
19+
static func expansion<
20+
Context: MacroExpansionContext,
21+
Declaration: DeclSyntaxProtocol
22+
>(
2023
of node: AttributeSyntax,
21-
providingPeersOf declaration: DeclSyntax,
24+
providingPeersOf declaration: Declaration,
2225
in context: Context
2326
) throws -> [DeclSyntax]
2427
}

Tests/SwiftSyntaxMacrosTest/MacroSystemTests.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,12 @@ extension PropertyWrapper: AccessorMacro {
294294
}
295295

296296
extension PropertyWrapper: PeerMacro {
297-
public static func expansion<Context: MacroExpansionContext>(
297+
public static func expansion<
298+
Context: MacroExpansionContext,
299+
Declaration: DeclSyntaxProtocol
300+
>(
298301
of node: AttributeSyntax,
299-
providingPeersOf declaration: DeclSyntax,
302+
providingPeersOf declaration: Declaration,
300303
in context: Context
301304
) throws -> [SwiftSyntax.DeclSyntax] {
302305
guard let varDecl = declaration.as(VariableDeclSyntax.self),
@@ -331,9 +334,12 @@ extension PropertyWrapper: PeerMacro {
331334
}
332335

333336
public struct AddCompletionHandler: PeerMacro {
334-
public static func expansion<Context: MacroExpansionContext>(
337+
public static func expansion<
338+
Context: MacroExpansionContext,
339+
Declaration: DeclSyntaxProtocol
340+
>(
335341
of node: AttributeSyntax,
336-
providingPeersOf declaration: DeclSyntax,
342+
providingPeersOf declaration: Declaration,
337343
in context: Context
338344
) throws -> [DeclSyntax] {
339345
// Only on functions at the moment. We could handle initializers as well

0 commit comments

Comments
 (0)