File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -6707,10 +6707,14 @@ bool ProtocolDecl::existentialConformsToSelf() const {
67076707}
67086708
67096709bool ProtocolDecl::hasSelfOrAssociatedTypeRequirements () const {
6710+ // Because we will have considered all the protocols in a cyclic hierarchy by
6711+ // the time the cycle is hit.
6712+ const bool resultForCycle = false ;
6713+
67106714 return evaluateOrDefault (getASTContext ().evaluator ,
67116715 HasSelfOrAssociatedTypeRequirementsRequest{
67126716 const_cast <ProtocolDecl *>(this )},
6713- true );
6717+ resultForCycle );
67146718}
67156719
67166720bool ProtocolDecl::existentialRequiresAny () const {
Original file line number Diff line number Diff line change 1+ // RUN: %target-typecheck-verify-swift -swift-version 5 -verify-additional-prefix no-explicit-any-
2+ // RUN: %target-typecheck-verify-swift -swift-version 5 -enable-upcoming-feature ExistentialAny -verify-additional-prefix explicit-any-
3+
4+ // REQUIRES: swift_feature_ExistentialAny
5+
6+ // 'HasSelfOrAssociatedTypeRequirementsRequest' should evaluate to false in
7+ // the event of a cycle because we will have considered all the protocols in a
8+ // cyclic hierarchy by the time the cycle is hit.
9+ do {
10+ do {
11+ protocol P1 : P2 { }
12+ // expected-no-explicit-any-note@-1 2 {{protocol 'P1' declared here}}
13+ // expected-explicit-any-note@-2 1 {{protocol 'P1' declared here}}
14+ protocol P2 : P1 { }
15+ // expected-no-explicit-any-error@-1 2 {{protocol 'P2' refines itself}}
16+ // expected-explicit-any-error@-2 1 {{protocol 'P2' refines itself}}
17+
18+ // Diagnosed only with the feature enabled, as a protocol without
19+ // "HasSelfOrAssociatedTypeRequirements" should.
20+ let _: P2
21+ // expected-explicit-any-error@-1 {{use of protocol 'P2' as a type must be written 'any P2'}}
22+ }
23+ do {
24+ protocol P0 { associatedtype A }
25+ protocol P1 : P2 , P0 { }
26+ // expected-no-explicit-any-note@-1 2 {{protocol 'P1' declared here}}
27+ // expected-explicit-any-note@-2 1 {{protocol 'P1' declared here}}
28+ protocol P2 : P1 { }
29+ // expected-no-explicit-any-error@-1 2 {{protocol 'P2' refines itself}}
30+ // expected-explicit-any-error@-2 1 {{protocol 'P2' refines itself}}
31+
32+ let _: P2
33+ // expected-error@-1 {{use of protocol 'P2' as a type must be written 'any P2'}}
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments