Skip to content

Commit d6b6631

Browse files
authored
Merge pull request #2319 from ahoppen/ahoppen/infinite-recursion
Throw an error if types conforming to `MemberMacro` implement no `expansion` method
2 parents ebd7026 + 8566db0 commit d6b6631

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Sources/SwiftSyntaxMacros/MacroProtocols/MemberMacro.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ 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:conformingTo:in:")
26+
///
27+
/// - Warning: This is the legacy `expansion` function of `MemberMacro` that is provided for backwards-compatiblity.
28+
/// Use ``expansion(of:providingMembersOf:conformingTo:in:)-1sxoe`` instead.
2729
static func expansion(
2830
of node: AttributeSyntax,
2931
providingMembersOf declaration: some DeclGroupSyntax,
@@ -54,14 +56,24 @@ public protocol MemberMacro: AttachedMacro {
5456
) throws -> [DeclSyntax]
5557
}
5658

59+
private struct UnimplementedExpansionMethodError: Error, CustomStringConvertible {
60+
var description: String {
61+
"""
62+
Types conforming to `MemberMacro` must implement either \
63+
expansion(of:providingMembersOf:in:) or \
64+
expansion(of:providingMembersOf:conformingTo:in:)
65+
"""
66+
}
67+
}
68+
5769
public extension MemberMacro {
5870
/// Default implementation supplies no conformances.
5971
static func expansion(
6072
of node: AttributeSyntax,
6173
providingMembersOf declaration: some DeclGroupSyntax,
6274
in context: some MacroExpansionContext
6375
) throws -> [DeclSyntax] {
64-
return try expansion(of: node, providingMembersOf: declaration, conformingTo: [], in: context)
76+
throw UnimplementedExpansionMethodError()
6577
}
6678

6779
/// Default implementation that ignores the unhandled conformances.

0 commit comments

Comments
 (0)