@@ -17,9 +17,35 @@ import SwiftDiagnostics
17
17
public enum DebugDescriptionMacro { }
18
18
public enum _DebugDescriptionPropertyMacro { }
19
19
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
+
20
46
/// A macro which orchestrates conversion of a description property to an LLDB type summary.
21
47
///
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
23
49
/// type, and then delegates to `@_DebugDescriptionProperty` to perform the conversion step.
24
50
extension DebugDescriptionMacro : MemberAttributeMacro {
25
51
public static func expansion(
@@ -31,8 +57,12 @@ extension DebugDescriptionMacro: MemberAttributeMacro {
31
57
throws -> [ AttributeSyntax ]
32
58
{
33
59
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.
36
66
return [ ]
37
67
}
38
68
0 commit comments