Skip to content

Commit be587c3

Browse files
committed
Sema: Compute the requirement signature before visiting protocol members
1 parent 54bf6ad commit be587c3

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,6 +2650,12 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
26502650

26512651
TypeChecker::checkDeclAttributes(PD);
26522652

2653+
// Explicity compute the requirement signature to detect errors.
2654+
// Do this before visiting members, to avoid a request cycle if
2655+
// a member referenecs another declaration whose generic signature
2656+
// has a conformance requirement to this protocol.
2657+
auto reqSig = PD->getRequirementSignature().getRequirements();
2658+
26532659
// Check the members.
26542660
for (auto Member : PD->getMembers())
26552661
visit(Member);
@@ -2663,9 +2669,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
26632669
if (!SF || SF->Kind != SourceFileKind::Interface)
26642670
TypeChecker::inferDefaultWitnesses(PD);
26652671

2666-
// Explicity compute the requirement signature to detect errors.
2667-
auto reqSig = PD->getRequirementSignature().getRequirements();
2668-
26692672
if (PD->getASTContext().TypeCheckerOpts.DebugGenericSignatures) {
26702673
auto requirementsSig =
26712674
GenericSignature::get({PD->getProtocolSelfType()}, reqSig);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
protocol P {
4+
associatedtype X
5+
associatedtype Y where Y : Q
6+
}
7+
8+
protocol Q {
9+
associatedtype T
10+
}
11+
12+
struct S: Q {
13+
typealias T = Int
14+
}
15+
16+
extension P where X == () {
17+
typealias Y = S
18+
}

0 commit comments

Comments
 (0)