|
| 1 | +// RUN: %target-typecheck-verify-swift |
| 2 | + |
| 3 | +protocol P1 where A == Never { |
| 4 | + associatedtype A // expected-note {{protocol requires nested type 'A'}} |
| 5 | +} |
| 6 | +// FIXME: Should this infer A := Never? |
| 7 | +struct S1: P1 {} // expected-error {{type 'S1' does not conform to protocol 'P1'}} |
| 8 | + |
| 9 | +protocol P2a { |
| 10 | + associatedtype A |
| 11 | +} |
| 12 | +protocol P2b: P2a where A == Never {} |
| 13 | +protocol P2c: P2b {} |
| 14 | +struct S2a: P2b {} // OK, A := Never |
| 15 | +struct S2b: P2c {} // OK, A := Never |
| 16 | + |
| 17 | +// Fixed type witnesses can reference dependent members. |
| 18 | +protocol P3a { |
| 19 | + associatedtype A |
| 20 | + associatedtype B |
| 21 | +} |
| 22 | +protocol P3b: P3a where A == [B] {} |
| 23 | +struct S3: P3b { // OK, A := [Never], B := Never |
| 24 | + typealias B = Never |
| 25 | +} |
| 26 | + |
| 27 | +protocol P4 {} |
| 28 | +extension P4 { |
| 29 | + typealias B = Self |
| 30 | +} |
| 31 | +struct S4: P4, P3b {} // OK, A := [S4], B := S4 |
| 32 | + |
| 33 | +// Self is a valid fixed type witness. |
| 34 | +protocol P5a { |
| 35 | + associatedtype A |
| 36 | +} |
| 37 | +protocol P5b: P5a where A == Self {} |
| 38 | +struct S5<X>: P5b {} // OK, A := S5<X> |
| 39 | + |
| 40 | + |
| 41 | +protocol P6 where A == Never { // expected-error {{same-type constraint type 'Never' does not conform to required protocol 'P6'}} |
| 42 | + // expected-error@+2 {{same-type constraint type 'Never' does not conform to required protocol 'P6'}} |
| 43 | + // expected-note@+1 {{protocol requires nested type 'A}} |
| 44 | + associatedtype A: P6 |
| 45 | +} |
| 46 | +struct S6: P6 {} // expected-error {{type 'S6' does not conform to protocol 'P6'}} |
| 47 | + |
| 48 | +protocol P7a where A == Never { |
| 49 | + associatedtype A |
| 50 | +} |
| 51 | +// expected-error@+2 {{'Self.A' cannot be equal to both 'Bool' and 'Never'}} |
| 52 | +// expected-note@+1 {{same-type constraint 'Self.A' == 'Never' implied here}} |
| 53 | +protocol P7b: P7a where A == Bool {} |
| 54 | +struct S7: P7b {} |
| 55 | + |
| 56 | +protocol P8 where A == Bool { |
| 57 | + associatedtype A // expected-note {{protocol requires nested type 'A'}} |
| 58 | +} |
| 59 | +// expected-error@+2 {{type 'S8' does not conform to protocol 'P7a'}} |
| 60 | +// expected-error@+1 {{type 'S8' does not conform to protocol 'P8'}} |
| 61 | +struct S8: P8, P7a {} |
| 62 | + |
| 63 | +protocol P9a where A == Never { |
| 64 | + associatedtype A |
| 65 | +} |
| 66 | +protocol P9b: P9a { |
| 67 | + associatedtype A // expected-note {{protocol requires nested type 'A'}} |
| 68 | +} |
| 69 | +// FIXME: Associated type restatement sabotages the conformance. |
| 70 | +// expected-error@+2 {{type 'S9a' does not conform to protocol 'P9a'}} |
| 71 | +// expected-error@+1 {{type 'S9a' does not conform to protocol 'P9b'}} |
| 72 | +struct S9a: P9b {} |
| 73 | +// expected-error@+2 {{'P9a' requires the types 'S9b.A' (aka 'Bool') and 'Never' be equivalent}} |
| 74 | +// expected-note@+1 {{requirement specified as 'Self.A' == 'Never' [with Self = S9b]}} |
| 75 | +struct S9b: P9b { |
| 76 | + typealias A = Bool |
| 77 | +} |
| 78 | +struct S9c: P9b { // OK, S9c.A does not contradict Self.A == Never. |
| 79 | + typealias Sugar = Never |
| 80 | + typealias A = Sugar |
| 81 | +} |
| 82 | + |
| 83 | +protocol P10 {} |
| 84 | +extension P10 { |
| 85 | + typealias A = Bool |
| 86 | +} |
| 87 | +// FIXME: 'P10 extension.A' should not be considered a viable type witness; |
| 88 | +// instead, the compiler should infer A := Never and synthesize S10.A. |
| 89 | +// expected-error@+2 {{'P9a' requires the types 'S10.A' (aka 'Bool') and 'Never' be equivalent}} |
| 90 | +// expected-note@+1 {{requirement specified as 'Self.A' == 'Never' [with Self = S10]}} |
| 91 | +struct S10: P10, P9a {} |
| 92 | + |
| 93 | +protocol P11a { |
| 94 | + associatedtype A |
| 95 | +} |
| 96 | +protocol P11b: P11a where A == Never {} |
| 97 | +protocol Q11 { |
| 98 | + associatedtype A // expected-note {{protocol requires nested type 'A'}} |
| 99 | +} |
| 100 | +// FIXME: Unrelated protocols with a matching associated type should |
| 101 | +// also be considered when computing a fixed type witness. |
| 102 | +// expected-error@+3 {{type 'S11' does not conform to protocol 'Q11'}} |
| 103 | +// expected-error@+2 {{type 'S11' does not conform to protocol 'P11a'}} |
| 104 | +// expected-error@+1 {{type 'S11' does not conform to protocol 'P11b'}} |
| 105 | +struct S11: Q11, P11b {} |
0 commit comments