Skip to content

Commit b631480

Browse files
committed
RequirementMachine: Add a small test case
1 parent 66ab887 commit b631480

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// RUN: %target-typecheck-verify-swift -enable-requirement-machine
2+
3+
// Make sure the requirement machine can compute a confluent
4+
// completion in examples where we merge two associated types
5+
// with the same name, both having recursive conformance
6+
// requirements.
7+
8+
// Merged two cycles of length 1:
9+
//
10+
// P1 -> P1 -> P1 -> ...
11+
// P2 -> P2 -> P2 -> ...
12+
protocol P1 {
13+
associatedtype T : P1
14+
}
15+
16+
protocol P2 {
17+
associatedtype T : P2
18+
}
19+
20+
struct S<T : P1 & P2> {}
21+
22+
// Merged a cycle of length 2 with a cycle of length 3
23+
//
24+
// P1a -> P1b -> P1a -> P1b -> P1a -> P1b -> ...
25+
// P2a -> P2b -> P2c -> P2a -> P2b -> P2c -> ...
26+
protocol P1a {
27+
associatedtype T : P1b
28+
}
29+
30+
protocol P1b {
31+
associatedtype T : P1a
32+
}
33+
34+
protocol P2a {
35+
associatedtype T : P2b
36+
}
37+
38+
protocol P2b {
39+
associatedtype T : P2c
40+
}
41+
42+
protocol P2c {
43+
associatedtype T : P2a
44+
}
45+
46+
struct SS<T : P1a & P2a> {}
47+
48+
// Merged two cycles of length 1 via an inherited associated type
49+
protocol Base {
50+
associatedtype T : Base // expected-note {{'T' declared here}}
51+
}
52+
53+
// Base -> Base -> Base -> ...
54+
// Derived1 -> Derived1 -> Derived1 -> ...
55+
protocol Derived1 : Base {
56+
associatedtype T : Derived1 // expected-warning {{redeclaration of associated type 'T' from protocol 'Base' is better expressed as a 'where' clause on the protocol}}
57+
}
58+
59+
// Base -> Base -> Base -> ...
60+
// Derived2 -> Derived2 -> Derived2 -> ...
61+
protocol Derived2 : Base where T : Derived2 {}

0 commit comments

Comments
 (0)