diff --git a/lib/Sema/TypeCheckDeclPrimary.cpp b/lib/Sema/TypeCheckDeclPrimary.cpp index 77383c1c10f..0686b3f3828 100644 --- a/lib/Sema/TypeCheckDeclPrimary.cpp +++ b/lib/Sema/TypeCheckDeclPrimary.cpp @@ -2650,6 +2650,12 @@ public: TypeChecker::checkDeclAttributes(PD); + // Explicity compute the requirement signature to detect errors. + // Do this before visiting members, to avoid a request cycle if + // a member referenecs another declaration whose generic signature + // has a conformance requirement to this protocol. + auto reqSig = PD->getRequirementSignature().getRequirements(); + // Check the members. for (auto Member : PD->getMembers()) visit(Member); @@ -2663,9 +2669,6 @@ public: if (!SF || SF->Kind != SourceFileKind::Interface) TypeChecker::inferDefaultWitnesses(PD); - // Explicity compute the requirement signature to detect errors. - auto reqSig = PD->getRequirementSignature().getRequirements(); - if (PD->getASTContext().TypeCheckerOpts.DebugGenericSignatures) { auto requirementsSig = GenericSignature::get({PD->getProtocolSelfType()}, reqSig); diff --git a/test/Generics/protocol_typealias_cycle_1a.swift b/test/Generics/protocol_typealias_cycle_1a.swift new file mode 100644 index 00000000000..cbde0c7ff9e --- /dev/null +++ b/test/Generics/protocol_typealias_cycle_1a.swift @@ -0,0 +1,18 @@ +// RUN: %target-typecheck-verify-swift + +protocol P { + associatedtype X + associatedtype Y where Y : Q +} + +protocol Q { + associatedtype T +} + +struct S: Q { + typealias T = Int +} + +extension P where X == () { + typealias Y = S +}