@@ -1243,9 +1243,16 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
1243
1243
void visitProtocolType (ProtocolType *PT,
1244
1244
Optional<OptionalTypeKind> optionalKind,
1245
1245
bool isMetatype = false ) {
1246
+ auto proto = PT->getDecl ();
1247
+ if (proto->isSpecificProtocol (KnownProtocolKind::Error)) {
1248
+ if (isMetatype) os << " Class" ;
1249
+ else os << " NSError *" ;
1250
+ printNullability (optionalKind);
1251
+ return ;
1252
+ }
1253
+
1246
1254
os << (isMetatype ? " Class" : " id" );
1247
1255
1248
- auto proto = PT->getDecl ();
1249
1256
assert (proto->isObjC ());
1250
1257
if (auto knownKind = proto->getKnownProtocolKind ()) {
1251
1258
if (*knownKind == KnownProtocolKind::AnyObject) {
@@ -1266,15 +1273,27 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
1266
1273
return visitProtocolType (singleProto, optionalKind, isMetatype);
1267
1274
PCT = cast<ProtocolCompositionType>(canonicalComposition);
1268
1275
1269
- os << (isMetatype ? " Class " : " id " );
1270
-
1276
+ // Dig out the protocols. If we see 'Error', record that we saw it.
1277
+ bool hasError = false ;
1271
1278
SmallVector<ProtocolDecl *, 4 > protos;
1272
- std::transform (PCT->getProtocols ().begin (), PCT->getProtocols ().end (),
1273
- std::back_inserter (protos),
1274
- [] (Type ty) -> ProtocolDecl * {
1275
- return ty->castTo <ProtocolType>()->getDecl ();
1276
- });
1279
+ for (auto protoTy : PCT->getProtocols ()) {
1280
+ auto proto = protoTy->castTo <ProtocolType>()->getDecl ();
1281
+ if (proto->isSpecificProtocol (KnownProtocolKind::Error)) {
1282
+ hasError = true ;
1283
+ continue ;
1284
+ }
1285
+
1286
+ protos.push_back (proto);
1287
+ }
1288
+
1289
+ os << (isMetatype ? " Class"
1290
+ : hasError ? " NSError"
1291
+ : " id" );
1277
1292
printProtocols (protos);
1293
+
1294
+ if (hasError && !isMetatype)
1295
+ os << " *" ;
1296
+
1278
1297
printNullability (optionalKind);
1279
1298
}
1280
1299
@@ -1630,7 +1649,8 @@ class ModuleWriter {
1630
1649
1631
1650
void forwardDeclare (const ProtocolDecl *PD) {
1632
1651
assert (PD->isObjC () ||
1633
- *PD->getKnownProtocolKind () == KnownProtocolKind::AnyObject);
1652
+ *PD->getKnownProtocolKind () == KnownProtocolKind::AnyObject ||
1653
+ *PD->getKnownProtocolKind () == KnownProtocolKind::Error);
1634
1654
forwardDeclare (PD, [&]{
1635
1655
os << " @protocol " << getNameForObjC (PD) << " ;\n " ;
1636
1656
});
0 commit comments