@@ -17,9 +17,35 @@ import SwiftDiagnostics
1717public enum DebugDescriptionMacro { }
1818public enum _DebugDescriptionPropertyMacro { }
1919
20+ /// The member role is used only to perform diagnostics. The member role ensures any diagnostics are emitted once per
21+ /// type. The macro's core behavior begins with the `MemberAttributeMacro` conformance.
22+ extension DebugDescriptionMacro : MemberMacro {
23+ public static func expansion(
24+ of node: AttributeSyntax ,
25+ providingMembersOf declaration: some DeclGroupSyntax ,
26+ in context: some MacroExpansionContext
27+ )
28+ throws -> [ DeclSyntax ]
29+ {
30+ guard !declaration. is ( ProtocolDeclSyntax . self) else {
31+ let message : ErrorMessage = " cannot be attached to a protocol "
32+ context. diagnose ( node: node, error: message)
33+ return [ ]
34+ }
35+
36+ guard declaration. asProtocol ( WithGenericParametersSyntax . self) ? . genericParameterClause == nil else {
37+ let message : ErrorMessage = " cannot be attached to a generic definition "
38+ context. diagnose ( node: node, error: message)
39+ return [ ]
40+ }
41+
42+ return [ ]
43+ }
44+ }
45+
2046/// A macro which orchestrates conversion of a description property to an LLDB type summary.
2147///
22- /// The job of conversion is split across two macros. This macro performs some analysis on the attached
48+ /// The process of conversion is split across multiple macros/roles . This role performs some analysis on the attached
2349/// type, and then delegates to `@_DebugDescriptionProperty` to perform the conversion step.
2450extension DebugDescriptionMacro : MemberAttributeMacro {
2551 public static func expansion(
@@ -31,8 +57,12 @@ extension DebugDescriptionMacro: MemberAttributeMacro {
3157 throws -> [ AttributeSyntax ]
3258 {
3359 guard !declaration. is ( ProtocolDeclSyntax . self) else {
34- let message : ErrorMessage = " cannot be attached to a protocol "
35- context. diagnose ( node: node, error: message)
60+ // Diagnostics for this case are emitted by the `MemberMacro` conformance.
61+ return [ ]
62+ }
63+
64+ guard declaration. asProtocol ( WithGenericParametersSyntax . self) ? . genericParameterClause == nil else {
65+ // Diagnostics for this case are emitted by the `MemberMacro` conformance.
3666 return [ ]
3767 }
3868
0 commit comments