@@ -2674,24 +2674,30 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
26742674 NTD->diagnose (diag::tuple_extension_nested_type, NTD);
26752675 return ;
26762676 }
2677+ }
26772678
2678- // We don't support protocols outside the top level of a file.
2679- if (isa<ProtocolDecl>(NTD) &&
2680- !DC->isModuleScopeContext ()) {
2681- NTD->diagnose (diag::unsupported_nested_protocol, NTD);
2682- NTD->setInvalid ();
2683- return ;
2684- }
2679+ // We don't support protocols nested in generic contexts.
2680+ // This includes protocols nested in other protocols.
2681+ if (isa<ProtocolDecl>(NTD) && NTD->getParent ()->isGenericContext ()) {
2682+ if (auto *OuterPD = NTD->getParent ()->getSelfProtocolDecl ())
2683+ NTD->diagnose (diag::unsupported_nested_protocol_in_protocol, NTD,
2684+ OuterPD);
2685+ else
2686+ NTD->diagnose (diag::unsupported_nested_protocol_in_generic, NTD);
26852687
2686- // We don't support nested types in protocols.
2687- if (auto proto = dyn_cast<ProtocolDecl>(parentDecl)) {
2688- if (DC->getExtendedProtocolDecl ()) {
2689- NTD->diagnose (diag::unsupported_type_nested_in_protocol_extension, NTD,
2690- proto);
2691- } else {
2692- NTD->diagnose (diag::unsupported_type_nested_in_protocol, NTD, proto);
2693- }
2688+ NTD->setInvalid ();
2689+ return ;
2690+ }
2691+
2692+ // We don't support nested types in protocols.
2693+ if (auto proto = dyn_cast<ProtocolDecl>(parentDecl)) {
2694+ if (DC->getExtendedProtocolDecl ()) {
2695+ NTD->diagnose (diag::unsupported_type_nested_in_protocol_extension, NTD,
2696+ proto);
2697+ } else {
2698+ NTD->diagnose (diag::unsupported_type_nested_in_protocol, NTD, proto);
26942699 }
2700+ NTD->setInvalid ();
26952701 }
26962702
26972703 // We don't support nested types in generic functions yet.
@@ -2704,6 +2710,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
27042710 } else {
27052711 NTD->diagnose (diag::unsupported_type_nested_in_generic_closure, NTD);
27062712 }
2713+ NTD->setInvalid ();
27072714 }
27082715 }
27092716 }
@@ -3182,6 +3189,15 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
31823189 if (!PD->getPrimaryAssociatedTypeNames ().empty ())
31833190 (void ) PD->getPrimaryAssociatedTypes ();
31843191
3192+ // We cannot compute the requirement signature of a protocol
3193+ // in a generic context, because superclass constraints
3194+ // may include implicitly inferred generic arguments that are
3195+ // not part of the protocol's generic signature.
3196+ if (PD->getParent ()->isGenericContext ()) {
3197+ assert (PD->isInvalid ());
3198+ return ;
3199+ }
3200+
31853201 // Explicitly compute the requirement signature to detect errors.
31863202 // Do this before visiting members, to avoid a request cycle if
31873203 // a member references another declaration whose generic signature
0 commit comments