@@ -2409,21 +2409,10 @@ static bool usesFeatureAsyncAwait(Decl *decl) {
2409
2409
}
2410
2410
2411
2411
static bool usesFeatureMarkerProtocol (Decl *decl) {
2412
- if (auto proto = dyn_cast<ProtocolDecl>(decl)) {
2413
- if (proto->isMarkerProtocol ())
2414
- return true ;
2415
- }
2416
-
2417
- if (auto ext = dyn_cast<ExtensionDecl>(decl)) {
2418
- for (const auto &req: ext->getGenericRequirements ()) {
2419
- if (req.getKind () == RequirementKind::Conformance &&
2420
- req.getSecondType ()->castTo <ProtocolType>()->getDecl ()
2421
- ->isMarkerProtocol ())
2422
- return true ;
2423
- }
2424
-
2425
- for (const auto &inherited : ext->getInherited ()) {
2426
- if (auto inheritedType = inherited.getType ()) {
2412
+ // Check an inheritance clause for a marker protocol.
2413
+ auto checkInherited = [&](ArrayRef<TypeLoc> inherited) -> bool {
2414
+ for (const auto &inheritedEntry : inherited) {
2415
+ if (auto inheritedType = inheritedEntry.getType ()) {
2427
2416
if (inheritedType->isExistentialType ()) {
2428
2417
auto layout = inheritedType->getExistentialLayout ();
2429
2418
for (ProtocolType *protoTy : layout.getProtocols ()) {
@@ -2433,6 +2422,39 @@ static bool usesFeatureMarkerProtocol(Decl *decl) {
2433
2422
}
2434
2423
}
2435
2424
}
2425
+
2426
+ return false ;
2427
+ };
2428
+
2429
+ // Check generic requirements for a marker protocol.
2430
+ auto checkRequirements = [&](ArrayRef<Requirement> requirements) -> bool {
2431
+ for (const auto &req: requirements) {
2432
+ if (req.getKind () == RequirementKind::Conformance &&
2433
+ req.getSecondType ()->castTo <ProtocolType>()->getDecl ()
2434
+ ->isMarkerProtocol ())
2435
+ return true ;
2436
+ }
2437
+
2438
+ return false ;
2439
+ };
2440
+
2441
+ if (auto proto = dyn_cast<ProtocolDecl>(decl)) {
2442
+ if (proto->isMarkerProtocol ())
2443
+ return true ;
2444
+
2445
+ if (checkInherited (proto->getInherited ()))
2446
+ return true ;
2447
+
2448
+ if (checkRequirements (proto->getRequirementSignature ()))
2449
+ return true ;
2450
+ }
2451
+
2452
+ if (auto ext = dyn_cast<ExtensionDecl>(decl)) {
2453
+ if (checkRequirements (ext->getGenericRequirements ()))
2454
+ return true ;
2455
+
2456
+ if (checkInherited (ext->getInherited ()))
2457
+ return true ;
2436
2458
}
2437
2459
2438
2460
return false ;
@@ -5377,9 +5399,10 @@ swift::getInheritedForPrinting(const Decl *decl, const PrintOptions &options,
5377
5399
return true ;
5378
5400
5379
5401
if (auto PD = dyn_cast<ProtocolDecl>(NTD)) {
5380
- // Marker protocols are unprintable on nominal types, but they're
5381
- // okay on extension declarations.
5382
- if (PD->isMarkerProtocol () && !isa<ExtensionDecl>(decl))
5402
+ // Marker protocols are unprintable on concrete types, but they're
5403
+ // okay on extension declarations and protocols.
5404
+ if (PD->isMarkerProtocol () && !isa<ExtensionDecl>(decl) &&
5405
+ !isa<ProtocolDecl>(decl))
5383
5406
return true ;
5384
5407
}
5385
5408
}
0 commit comments