@@ -79,7 +79,8 @@ public struct OptionSetMacro {
79
79
static func decodeExpansion(
80
80
of attribute: AttributeSyntax ,
81
81
attachedTo decl: some DeclGroupSyntax ,
82
- in context: some MacroExpansionContext
82
+ in context: some MacroExpansionContext ,
83
+ emitDiagnostics: Bool
83
84
) -> ( StructDeclSyntax , EnumDeclSyntax , TypeSyntax ) ? {
84
85
// Determine the name of the options enum.
85
86
let optionsEnumName : String
@@ -91,7 +92,9 @@ public struct OptionSetMacro {
91
92
stringLiteral. segments. count == 1 ,
92
93
case let . stringSegment( optionsEnumNameString) ? = stringLiteral. segments. first
93
94
else {
94
- context. diagnose ( OptionSetMacroDiagnostic . requiresStringLiteral ( optionsEnumNameArgumentLabel) . diagnose ( at: optionEnumNameArg. expression) )
95
+ if emitDiagnostics {
96
+ context. diagnose ( OptionSetMacroDiagnostic . requiresStringLiteral ( optionsEnumNameArgumentLabel) . diagnose ( at: optionEnumNameArg. expression) )
97
+ }
95
98
return nil
96
99
}
97
100
@@ -102,7 +105,9 @@ public struct OptionSetMacro {
102
105
103
106
// Only apply to structs.
104
107
guard let structDecl = decl. as ( StructDeclSyntax . self) else {
105
- context. diagnose ( OptionSetMacroDiagnostic . requiresStruct. diagnose ( at: decl) )
108
+ if emitDiagnostics {
109
+ context. diagnose ( OptionSetMacroDiagnostic . requiresStruct. diagnose ( at: decl) )
110
+ }
106
111
return nil
107
112
}
108
113
@@ -118,15 +123,19 @@ public struct OptionSetMacro {
118
123
return nil
119
124
} ) . first
120
125
else {
121
- context. diagnose ( OptionSetMacroDiagnostic . requiresOptionsEnum ( optionsEnumName) . diagnose ( at: decl) )
126
+ if emitDiagnostics {
127
+ context. diagnose ( OptionSetMacroDiagnostic . requiresOptionsEnum ( optionsEnumName) . diagnose ( at: decl) )
128
+ }
122
129
return nil
123
130
}
124
131
125
132
// Retrieve the raw type from the attribute.
126
133
guard let genericArgs = attribute. attributeName. as ( IdentifierTypeSyntax . self) ? . genericArgumentClause,
127
134
let rawType = genericArgs. arguments. first? . argument
128
135
else {
129
- context. diagnose ( OptionSetMacroDiagnostic . requiresOptionsEnumRawType. diagnose ( at: attribute) )
136
+ if emitDiagnostics {
137
+ context. diagnose ( OptionSetMacroDiagnostic . requiresOptionsEnumRawType. diagnose ( at: attribute) )
138
+ }
130
139
return nil
131
140
}
132
141
@@ -143,7 +152,7 @@ extension OptionSetMacro: ExtensionMacro {
143
152
in context: some MacroExpansionContext
144
153
) throws -> [ ExtensionDeclSyntax ] {
145
154
// Decode the expansion arguments.
146
- guard let ( structDecl, _, _) = decodeExpansion ( of: node, attachedTo: declaration, in: context) else {
155
+ guard let ( structDecl, _, _) = decodeExpansion ( of: node, attachedTo: declaration, in: context, emitDiagnostics : false ) else {
147
156
return [ ]
148
157
}
149
158
@@ -165,7 +174,7 @@ extension OptionSetMacro: MemberMacro {
165
174
in context: some MacroExpansionContext
166
175
) throws -> [ DeclSyntax ] {
167
176
// Decode the expansion arguments.
168
- guard let ( _, optionsEnum, rawType) = decodeExpansion ( of: attribute, attachedTo: decl, in: context) else {
177
+ guard let ( _, optionsEnum, rawType) = decodeExpansion ( of: attribute, attachedTo: decl, in: context, emitDiagnostics : true ) else {
169
178
return [ ]
170
179
}
171
180
0 commit comments