Sema: Compute the requirement signature before visiting protocol members

This commit is contained in:
Slava Pestov
2022-02-23 16:38:13 -05:00
parent 54bf6adb58
commit be587c3aa4
2 changed files with 24 additions and 3 deletions

View File

@@ -2650,6 +2650,12 @@ public:
TypeChecker::checkDeclAttributes(PD); 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. // Check the members.
for (auto Member : PD->getMembers()) for (auto Member : PD->getMembers())
visit(Member); visit(Member);
@@ -2663,9 +2669,6 @@ public:
if (!SF || SF->Kind != SourceFileKind::Interface) if (!SF || SF->Kind != SourceFileKind::Interface)
TypeChecker::inferDefaultWitnesses(PD); TypeChecker::inferDefaultWitnesses(PD);
// Explicity compute the requirement signature to detect errors.
auto reqSig = PD->getRequirementSignature().getRequirements();
if (PD->getASTContext().TypeCheckerOpts.DebugGenericSignatures) { if (PD->getASTContext().TypeCheckerOpts.DebugGenericSignatures) {
auto requirementsSig = auto requirementsSig =
GenericSignature::get({PD->getProtocolSelfType()}, reqSig); GenericSignature::get({PD->getProtocolSelfType()}, reqSig);

View File

@@ -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
}