|
| 1 | +// RUN: %target-typecheck-verify-swift |
| 2 | + |
| 3 | +protocol P {} |
| 4 | +struct X: P {} |
| 5 | +struct Y {} |
| 6 | + |
| 7 | +protocol AssociatedType { |
| 8 | + associatedtype T |
| 9 | +} |
| 10 | +struct Z1: AssociatedType { |
| 11 | + typealias T = X |
| 12 | +} |
| 13 | +struct Z2: AssociatedType { |
| 14 | + typealias T = Y |
| 15 | +} |
| 16 | + |
| 17 | +struct SameType<T> {} |
| 18 | +extension SameType where T == X { |
| 19 | + typealias TypeAlias1 = T |
| 20 | + typealias TypeAlias2 = Y |
| 21 | + typealias TypeAlias3<U> = (T, U) // expected-note {{requirement specified as 'T' == 'X' [with T = Y]}} |
| 22 | + |
| 23 | + struct Decl1 {} |
| 24 | + enum Decl2 {} |
| 25 | + class Decl3 {} |
| 26 | + struct Decl4<U> {} // expected-note 17 {{requirement specified as 'T' == 'X' [with T = Y]}} |
| 27 | + enum Decl5<U: P> {} // expected-note {{requirement specified as 'T' == 'X' [with T = Y]}} |
| 28 | +} |
| 29 | + |
| 30 | +let _ = SameType<X>.TypeAlias1.self |
| 31 | +let _ = SameType<X>.TypeAlias2.self |
| 32 | +let _ = SameType<X>.TypeAlias3<X>.self |
| 33 | +let _ = SameType<X>.Decl1.self |
| 34 | +let _ = SameType<X>.Decl2.self |
| 35 | +let _ = SameType<X>.Decl3.self |
| 36 | +let _ = SameType<X>.Decl4<X>.self |
| 37 | +let _ = SameType<X>.Decl5<X>.self |
| 38 | + |
| 39 | +let _ = SameType<Y>.TypeAlias1.self // expected-error {{'SameType<Y>.TypeAlias1.Type' (aka 'X.Type') requires the types 'Y' and 'X' be equivalent}} |
| 40 | +let _ = SameType<Y>.TypeAlias2.self // expected-error {{'SameType<Y>.TypeAlias2.Type' (aka 'Y.Type') requires the types 'Y' and 'X' be equivalent}} |
| 41 | +let _ = SameType<Y>.TypeAlias3<X>.self // expected-error {{'SameType<Y>.TypeAlias3' requires the types 'Y' and 'X' be equivalent}} |
| 42 | +let _ = SameType<Y>.Decl1.self // expected-error {{'SameType<Y>.Decl1.Type' requires the types 'Y' and 'X' be equivalent}} |
| 43 | +let _ = SameType<Y>.Decl2.self // expected-error {{'SameType<Y>.Decl2.Type' requires the types 'Y' and 'X' be equivalent}} |
| 44 | +let _ = SameType<Y>.Decl3.self // expected-error {{'SameType<Y>.Decl3.Type' requires the types 'Y' and 'X' be equivalent}} |
| 45 | +let _ = SameType<Y>.Decl4<X>.self // expected-error {{'SameType<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}} |
| 46 | +let _ = SameType<Y>.Decl5<X>.self // expected-error {{'SameType<Y>.Decl5' requires the types 'Y' and 'X' be equivalent}} |
| 47 | + |
| 48 | +struct Conforms<T> {} |
| 49 | +extension Conforms where T: P { |
| 50 | + typealias TypeAlias1 = T |
| 51 | + typealias TypeAlias2 = Y |
| 52 | + typealias TypeAlias3<U> = (T, U) |
| 53 | + |
| 54 | + struct Decl1 {} |
| 55 | + enum Decl2 {} |
| 56 | + class Decl3 {} |
| 57 | + struct Decl4<U> {} |
| 58 | + enum Decl5<U: P> {} |
| 59 | +} |
| 60 | + |
| 61 | +let _ = Conforms<X>.TypeAlias1.self |
| 62 | +let _ = Conforms<X>.TypeAlias2.self |
| 63 | +let _ = Conforms<X>.TypeAlias3<X>.self |
| 64 | +let _ = Conforms<X>.Decl1.self |
| 65 | +let _ = Conforms<X>.Decl2.self |
| 66 | +let _ = Conforms<X>.Decl3.self |
| 67 | +let _ = Conforms<X>.Decl4<X>.self |
| 68 | +let _ = Conforms<X>.Decl5<X>.self |
| 69 | + |
| 70 | +let _ = Conforms<Y>.TypeAlias1.self // expected-error {{type 'Y' does not conform to protocol 'P'}} |
| 71 | +let _ = Conforms<Y>.TypeAlias2.self // expected-error {{type 'Y' does not conform to protocol 'P'}} |
| 72 | +let _ = Conforms<Y>.TypeAlias3<X>.self // expected-error {{type 'Y' does not conform to protocol 'P'}} |
| 73 | +let _ = Conforms<Y>.Decl1.self // expected-error {{type 'Y' does not conform to protocol 'P'}} |
| 74 | +let _ = Conforms<Y>.Decl2.self // expected-error {{type 'Y' does not conform to protocol 'P'}} |
| 75 | +let _ = Conforms<Y>.Decl3.self // expected-error {{type 'Y' does not conform to protocol 'P'}} |
| 76 | +let _ = Conforms<Y>.Decl4<X>.self // expected-error {{type 'Y' does not conform to protocol 'P'}} |
| 77 | +let _ = Conforms<Y>.Decl5<X>.self // expected-error {{type 'Y' does not conform to protocol 'P'}} |
| 78 | + |
| 79 | +// Now, even more nesting! |
| 80 | + |
| 81 | +extension SameType.Decl1 { |
| 82 | + typealias TypeAlias1 = T |
| 83 | + typealias TypeAlias2 = Y |
| 84 | + typealias TypeAlias3<U> = (T, U) // expected-note {{requirement specified as 'T' == 'X' [with T = Y]}} |
| 85 | + |
| 86 | + struct Decl1 {} |
| 87 | + enum Decl2 {} |
| 88 | + class Decl3 {} |
| 89 | + struct Decl4<U> {} // expected-note {{requirement specified as 'T' == 'X' [with T = Y]}} |
| 90 | + enum Decl5<U: P> {} // expected-note {{requirement specified as 'T' == 'X' [with T = Y]}} |
| 91 | +} |
| 92 | + |
| 93 | +let _ = SameType<X>.Decl1.TypeAlias1.self |
| 94 | +let _ = SameType<X>.Decl1.TypeAlias2.self |
| 95 | +let _ = SameType<X>.Decl1.TypeAlias3<X>.self |
| 96 | +let _ = SameType<X>.Decl1.Decl1.self |
| 97 | +let _ = SameType<X>.Decl1.Decl2.self |
| 98 | +let _ = SameType<X>.Decl1.Decl3.self |
| 99 | +let _ = SameType<X>.Decl1.Decl4<X>.self |
| 100 | +let _ = SameType<X>.Decl1.Decl5<X>.self |
| 101 | + |
| 102 | +let _ = SameType<Y>.Decl1.TypeAlias1.self // expected-error {{'SameType<Y>.Decl1.TypeAlias1.Type' (aka 'X.Type') requires the types 'Y' and 'X' be equivalent}} |
| 103 | +let _ = SameType<Y>.Decl1.TypeAlias2.self // expected-error {{'SameType<Y>.Decl1.TypeAlias2.Type' (aka 'Y.Type') requires the types 'Y' and 'X' be equivalent}} |
| 104 | +let _ = SameType<Y>.Decl1.TypeAlias3<X>.self // expected-error {{'SameType<Y>.Decl1.TypeAlias3' requires the types 'Y' and 'X' be equivalent}} |
| 105 | +let _ = SameType<Y>.Decl1.Decl1.self // expected-error {{'SameType<Y>.Decl1.Decl1.Type' requires the types 'Y' and 'X' be equivalent}} |
| 106 | +let _ = SameType<Y>.Decl1.Decl2.self // expected-error {{'SameType<Y>.Decl1.Decl2.Type' requires the types 'Y' and 'X' be equivalent}} |
| 107 | +let _ = SameType<Y>.Decl1.Decl3.self // expected-error {{'SameType<Y>.Decl1.Decl3.Type' requires the types 'Y' and 'X' be equivalent}} |
| 108 | +let _ = SameType<Y>.Decl1.Decl4<X>.self // expected-error {{'SameType<Y>.Decl1.Decl4' requires the types 'Y' and 'X' be equivalent}} |
| 109 | +let _ = SameType<Y>.Decl1.Decl5<X>.self // expected-error {{'SameType<Y>.Decl1.Decl5' requires the types 'Y' and 'X' be equivalent}} |
| 110 | + |
| 111 | +extension SameType.Decl4 where U == X { |
| 112 | + typealias TypeAlias1 = T |
| 113 | + typealias TypeAlias2 = Y |
| 114 | + typealias TypeAlias3<V> = (T, U, V) // expected-note {{requirement specified as 'U' == 'X' [with U = Y]}} |
| 115 | + |
| 116 | + struct Decl1 {} |
| 117 | + enum Decl2 {} |
| 118 | + class Decl3 {} |
| 119 | + struct Decl4<V> {} // expected-note {{requirement specified as 'U' == 'X' [with U = Y]}} |
| 120 | + enum Decl5<V: P> {} // expected-note {{requirement specified as 'U' == 'X' [with U = Y]}} |
| 121 | +} |
| 122 | + |
| 123 | +// All the combinations |
| 124 | + |
| 125 | +let _ = SameType<X>.Decl4<X>.TypeAlias1.self |
| 126 | +let _ = SameType<X>.Decl4<X>.TypeAlias2.self |
| 127 | +let _ = SameType<X>.Decl4<X>.TypeAlias3<X>.self |
| 128 | +let _ = SameType<X>.Decl4<X>.Decl1.self |
| 129 | +let _ = SameType<X>.Decl4<X>.Decl2.self |
| 130 | +let _ = SameType<X>.Decl4<X>.Decl3.self |
| 131 | +let _ = SameType<X>.Decl4<X>.Decl4<X>.self |
| 132 | +let _ = SameType<X>.Decl4<X>.Decl5<X>.self |
| 133 | + |
| 134 | +let _ = SameType<X>.Decl4<Y>.TypeAlias1.self // expected-error {{'SameType<X>.Decl4<Y>.TypeAlias1.Type' (aka 'X.Type') requires the types 'Y' and 'X' be equivalent}} |
| 135 | +let _ = SameType<X>.Decl4<Y>.TypeAlias2.self // expected-error {{'SameType<X>.Decl4<Y>.TypeAlias2.Type' (aka 'Y.Type') requires the types 'Y' and 'X' be equivalent}} |
| 136 | +let _ = SameType<X>.Decl4<Y>.TypeAlias3<X>.self // expected-error {{'SameType<X>.Decl4<Y>.TypeAlias3' requires the types 'Y' and 'X' be equivalent}} |
| 137 | +let _ = SameType<X>.Decl4<Y>.Decl1.self // expected-error {{'SameType<X>.Decl4<Y>.Decl1.Type' requires the types 'Y' and 'X' be equivalent}} |
| 138 | +let _ = SameType<X>.Decl4<Y>.Decl2.self // expected-error {{'SameType<X>.Decl4<Y>.Decl2.Type' requires the types 'Y' and 'X' be equivalent}} |
| 139 | +let _ = SameType<X>.Decl4<Y>.Decl3.self // expected-error {{'SameType<X>.Decl4<Y>.Decl3.Type' requires the types 'Y' and 'X' be equivalent}} |
| 140 | +let _ = SameType<X>.Decl4<Y>.Decl4<X>.self // expected-error {{'SameType<X>.Decl4<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}} |
| 141 | +let _ = SameType<X>.Decl4<Y>.Decl5<X>.self // expected-error {{'SameType<X>.Decl4<Y>.Decl5' requires the types 'Y' and 'X' be equivalent}} |
| 142 | + |
| 143 | +let _ = SameType<Y>.Decl4<X>.TypeAlias1.self // expected-error {{'SameType<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}} |
| 144 | +let _ = SameType<Y>.Decl4<X>.TypeAlias2.self // expected-error {{'SameType<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}} |
| 145 | +let _ = SameType<Y>.Decl4<X>.TypeAlias3<X>.self // expected-error {{'SameType<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}} |
| 146 | +let _ = SameType<Y>.Decl4<X>.Decl1.self // expected-error {{'SameType<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}} |
| 147 | +let _ = SameType<Y>.Decl4<X>.Decl2.self // expected-error {{'SameType<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}} |
| 148 | +let _ = SameType<Y>.Decl4<X>.Decl3.self // expected-error {{'SameType<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}} |
| 149 | +let _ = SameType<Y>.Decl4<X>.Decl4<X>.self // expected-error {{'SameType<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}} |
| 150 | +let _ = SameType<Y>.Decl4<X>.Decl5<X>.self // expected-error {{'SameType<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}} |
| 151 | + |
| 152 | +let _ = SameType<Y>.Decl4<Y>.TypeAlias1.self // expected-error {{'SameType<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}} |
| 153 | +let _ = SameType<Y>.Decl4<Y>.TypeAlias2.self // expected-error {{'SameType<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}} |
| 154 | +let _ = SameType<Y>.Decl4<Y>.TypeAlias3<X>.self // expected-error {{'SameType<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}} |
| 155 | +let _ = SameType<Y>.Decl4<Y>.Decl1.self // expected-error {{'SameType<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}} |
| 156 | +let _ = SameType<Y>.Decl4<Y>.Decl2.self // expected-error {{'SameType<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}} |
| 157 | +let _ = SameType<Y>.Decl4<Y>.Decl3.self // expected-error {{'SameType<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}} |
| 158 | +let _ = SameType<Y>.Decl4<Y>.Decl4<X>.self // expected-error {{'SameType<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}} |
| 159 | +let _ = SameType<Y>.Decl4<Y>.Decl5<X>.self // expected-error {{'SameType<Y>.Decl4' requires the types 'Y' and 'X' be equivalent}} |
| 160 | + |
| 161 | +// Finally, extra complicated: |
| 162 | +extension Conforms.Decl4 where U: AssociatedType, U.T: P { |
| 163 | + typealias TypeAlias1 = T |
| 164 | + typealias TypeAlias2 = Y |
| 165 | + typealias TypeAlias3<V> = (T, U, V) |
| 166 | + |
| 167 | + struct Decl1 {} |
| 168 | + enum Decl2 {} |
| 169 | + class Decl3 {} |
| 170 | + struct Decl4<V> {} |
| 171 | + enum Decl5<V: P> {} |
| 172 | +} |
| 173 | + |
| 174 | +let _ = Conforms<X>.Decl4<Z1>.TypeAlias1.self |
| 175 | +let _ = Conforms<X>.Decl4<Z1>.TypeAlias2.self |
| 176 | +let _ = Conforms<X>.Decl4<Z1>.TypeAlias3<X>.self |
| 177 | +let _ = Conforms<X>.Decl4<Z1>.Decl1.self |
| 178 | +let _ = Conforms<X>.Decl4<Z1>.Decl2.self |
| 179 | +let _ = Conforms<X>.Decl4<Z1>.Decl3.self |
| 180 | +let _ = Conforms<X>.Decl4<Z1>.Decl4<X>.self |
| 181 | +let _ = Conforms<X>.Decl4<Z1>.Decl5<X>.self |
| 182 | + |
| 183 | +// Two different forms of badness, corresponding to the two requirements: |
| 184 | + |
| 185 | +let _ = Conforms<X>.Decl4<Y>.TypeAlias1.self // expected-error {{type 'Y' does not conform to protocol 'AssociatedType'}} |
| 186 | +let _ = Conforms<X>.Decl4<Y>.TypeAlias2.self // expected-error {{type 'Y' does not conform to protocol 'AssociatedType'}} |
| 187 | +let _ = Conforms<X>.Decl4<Y>.TypeAlias3<X>.self // expected-error {{type 'Y' does not conform to protocol 'AssociatedType'}} |
| 188 | +let _ = Conforms<X>.Decl4<Y>.Decl1.self // expected-error {{type 'Y' does not conform to protocol 'AssociatedType'}} |
| 189 | +let _ = Conforms<X>.Decl4<Y>.Decl2.self // expected-error {{type 'Y' does not conform to protocol 'AssociatedType'}} |
| 190 | +let _ = Conforms<X>.Decl4<Y>.Decl3.self // expected-error {{type 'Y' does not conform to protocol 'AssociatedType'}} |
| 191 | +let _ = Conforms<X>.Decl4<Y>.Decl4<X>.self // expected-error {{type 'Y' does not conform to protocol 'AssociatedType'}} |
| 192 | +let _ = Conforms<X>.Decl4<Y>.Decl5<X>.self // expected-error {{type 'Y' does not conform to protocol 'AssociatedType'}} |
| 193 | + |
| 194 | +let _ = Conforms<X>.Decl4<Z2>.TypeAlias1.self // expected-error {{type 'Z2.T' (aka 'Y') does not conform to protocol 'P'}} |
| 195 | +let _ = Conforms<X>.Decl4<Z2>.TypeAlias2.self // expected-error {{type 'Z2.T' (aka 'Y') does not conform to protocol 'P'}} |
| 196 | +let _ = Conforms<X>.Decl4<Z2>.TypeAlias3<X>.self // expected-error {{type 'Z2.T' (aka 'Y') does not conform to protocol 'P'}} |
| 197 | +let _ = Conforms<X>.Decl4<Z2>.Decl1.self // expected-error {{type 'Z2.T' (aka 'Y') does not conform to protocol 'P'}} |
| 198 | +let _ = Conforms<X>.Decl4<Z2>.Decl2.self // expected-error {{type 'Z2.T' (aka 'Y') does not conform to protocol 'P'}} |
| 199 | +let _ = Conforms<X>.Decl4<Z2>.Decl3.self // expected-error {{type 'Z2.T' (aka 'Y') does not conform to protocol 'P'}} |
| 200 | +let _ = Conforms<X>.Decl4<Z2>.Decl4<X>.self // expected-error {{type 'Z2.T' (aka 'Y') does not conform to protocol 'P'}} |
| 201 | +let _ = Conforms<X>.Decl4<Z2>.Decl5<X>.self // expected-error {{type 'Z2.T' (aka 'Y') does not conform to protocol 'P'}} |
0 commit comments