@@ -110,10 +110,8 @@ class DeclAndTypePrinter::Implementation
110
110
SmallVector<const FunctionType *, 4 > openFunctionTypes;
111
111
const DelayedMemberSet &delayedMembers;
112
112
113
- AccessLevel minRequiredAccess;
114
- bool protocolMembersOptional = false ;
115
-
116
113
Optional<Type> NSCopyingType;
114
+ AccessLevel minRequiredAccess;
117
115
118
116
public:
119
117
explicit Implementation (ModuleDecl &mod, raw_ostream &out,
@@ -189,6 +187,7 @@ class DeclAndTypePrinter::Implementation
189
187
// / Prints the members of a class, extension, or protocol.
190
188
template <bool AllowDelayed = false , typename R>
191
189
void printMembers (R &&members) {
190
+ bool protocolMembersOptional = false ;
192
191
for (const Decl *member : members) {
193
192
auto VD = dyn_cast<ValueDecl>(member);
194
193
if (!VD || !shouldInclude (VD) || isa<TypeDecl>(VD))
@@ -199,8 +198,9 @@ class DeclAndTypePrinter::Implementation
199
198
os << " // '" << VD->getFullName () << " ' below\n " ;
200
199
continue ;
201
200
}
202
- if (VD->getAttrs ().hasAttribute <OptionalAttr>() != protocolMembersOptional) {
203
- protocolMembersOptional = VD->getAttrs ().hasAttribute <OptionalAttr>();
201
+ if (VD->getAttrs ().hasAttribute <OptionalAttr>() !=
202
+ protocolMembersOptional) {
203
+ protocolMembersOptional = !protocolMembersOptional;
204
204
os << (protocolMembersOptional ? " @optional\n " : " @required\n " );
205
205
}
206
206
ASTVisitor::visit (const_cast <ValueDecl*>(VD));
@@ -364,9 +364,7 @@ class DeclAndTypePrinter::Implementation
364
364
365
365
printProtocols (PD->getInheritedProtocols ());
366
366
os << " \n " ;
367
- assert (!protocolMembersOptional && " protocols start required" );
368
367
printMembers (PD->getMembers ());
369
- protocolMembersOptional = false ;
370
368
os << " @end\n " ;
371
369
}
372
370
0 commit comments