@@ -101,24 +101,6 @@ func allMetasToAllMetas<T, U>(_: T.Type, _: U.Type) -> Bool {
101
101
return T . self is U . Type
102
102
}
103
103
104
- protocol P { }
105
- struct PS : P { }
106
- enum PE : P { }
107
- class PC : P { }
108
-
109
- func nongenericAnyIsP( type: Any . Type ) -> Bool {
110
- return type is P . Type
111
- }
112
- func genericAnyIs< T> ( type: Any . Type , to: T . Type ) -> Bool {
113
- return type is T . Type
114
- }
115
- print ( " nongenericAnyIsP(type: PS.self) " , nongenericAnyIsP ( type: PS . self) ) // CHECK: nongenericAnyIsP(type: PS.self) true
116
- print ( " genericAnyIs(type: PS.self, to: P.self) " , genericAnyIs ( type: PS . self, to: P . self) ) // CHECK-ONONE: genericAnyIs(type: PS.self, to: P.self) true
117
- print ( " nongenericAnyIsP(type: PE.self) " , nongenericAnyIsP ( type: PE . self) ) // CHECK: nongenericAnyIsP(type: PE.self) true
118
- print ( " genericAnyIs(type: PE.self, to: P.self) " , genericAnyIs ( type: PE . self, to: P . self) ) // CHECK-ONONE: genericAnyIs(type: PE.self, to: P.self) true
119
- print ( " nongenericAnyIsP(type: PC.self) " , nongenericAnyIsP ( type: PC . self) ) // CHECK: nongenericAnyIsP(type: PC.self) true
120
- print ( " genericAnyIs(type: PC.self, to: P.self) " , genericAnyIs ( type: PC . self, to: P . self) ) // CHECK-ONONE: genericAnyIs(type: PC.self, to: P.self) true
121
-
122
104
print ( allToInt ( 22 ) ) // CHECK: 22
123
105
print ( anyToInt ( 44 ) ) // CHECK: 44
124
106
allToC ( C ( ) ) . print ( ) // CHECK: C!
@@ -149,6 +131,73 @@ anyClassToCOrE(C()).print() // CHECK: C!
149
131
anyClassToCOrE ( D ( ) ) . print ( ) // CHECK: D!
150
132
anyClassToCOrE ( X ( ) ) . print ( ) // CHECK: E!
151
133
134
+ protocol P { }
135
+ @objc protocol PObjC { }
136
+ struct PS : P { }
137
+ enum PE : P { }
138
+ class PC : P , PObjC { }
139
+ class PCSub : PC { }
140
+
141
+ func nongenericAnyIsP( type: Any . Type ) -> Bool {
142
+ return type is P . Type
143
+ }
144
+ func nongenericAnyIsPObjC( type: Any . Type ) -> Bool {
145
+ return type is PObjC . Type
146
+ }
147
+ func nongenericAnyIsPAndAnyObject( type: Any . Type ) -> Bool {
148
+ return type is ( P & AnyObject ) . Type
149
+ }
150
+ func nongenericAnyIsPAndPCSub( type: Any . Type ) -> Bool {
151
+ return type is ( P & PCSub ) . Type
152
+ }
153
+ func genericAnyIs< T> ( type: Any . Type , to: T . Type ) -> Bool {
154
+ return type is T . Type
155
+ }
156
+ // CHECK-LABEL: casting types to protocols with generics:
157
+ print ( " casting types to protocols with generics: " )
158
+ print ( nongenericAnyIsP ( type: PS . self) ) // CHECK: true
159
+ print ( genericAnyIs ( type: PS . self, to: P . self) ) // CHECK-ONONE: true
160
+ print ( nongenericAnyIsP ( type: PE . self) ) // CHECK: true
161
+ print ( genericAnyIs ( type: PE . self, to: P . self) ) // CHECK-ONONE: true
162
+ print ( nongenericAnyIsP ( type: PC . self) ) // CHECK: true
163
+ print ( genericAnyIs ( type: PC . self, to: P . self) ) // CHECK-ONONE: true
164
+ print ( nongenericAnyIsP ( type: PCSub . self) ) // CHECK: true
165
+ print ( genericAnyIs ( type: PCSub . self, to: P . self) ) // CHECK-ONONE: true
166
+
167
+ // CHECK-LABEL: casting types to ObjC protocols with generics:
168
+ print ( " casting types to ObjC protocols with generics: " )
169
+ print ( nongenericAnyIsPObjC ( type: PS . self) ) // CHECK: false
170
+ print ( genericAnyIs ( type: PS . self, to: PObjC . self) ) // CHECK: false
171
+ print ( nongenericAnyIsPObjC ( type: PE . self) ) // CHECK: false
172
+ print ( genericAnyIs ( type: PE . self, to: PObjC . self) ) // CHECK: false
173
+ print ( nongenericAnyIsPObjC ( type: PC . self) ) // CHECK: true
174
+ print ( genericAnyIs ( type: PC . self, to: PObjC . self) ) // CHECK-ONONE: true
175
+ print ( nongenericAnyIsPObjC ( type: PCSub . self) ) // CHECK: true
176
+ print ( genericAnyIs ( type: PCSub . self, to: PObjC . self) ) // CHECK-ONONE: true
177
+
178
+ // CHECK-LABEL: casting types to protocol & AnyObject existentials:
179
+ print ( " casting types to protocol & AnyObject existentials: " )
180
+ print ( nongenericAnyIsPAndAnyObject ( type: PS . self) ) // CHECK: false
181
+ print ( genericAnyIs ( type: PS . self, to: ( P & AnyObject) . self) ) // CHECK: false
182
+ print ( nongenericAnyIsPAndAnyObject ( type: PE . self) ) // CHECK: false
183
+ print ( genericAnyIs ( type: PE . self, to: ( P & AnyObject) . self) ) // CHECK: false
184
+ print ( nongenericAnyIsPAndAnyObject ( type: PC . self) ) // CHECK: true
185
+ print ( genericAnyIs ( type: PC . self, to: ( P & AnyObject) . self) ) // CHECK-ONONE: true
186
+ print ( nongenericAnyIsPAndAnyObject ( type: PCSub . self) ) // CHECK: true
187
+ print ( genericAnyIs ( type: PCSub . self, to: ( P & AnyObject) . self) ) // CHECK-ONONE: true
188
+
189
+ // CHECK-LABEL: casting types to protocol & class existentials:
190
+ print ( " casting types to protocol & class existentials: " )
191
+ print ( nongenericAnyIsPAndPCSub ( type: PS . self) ) // CHECK: false
192
+ print ( genericAnyIs ( type: PS . self, to: ( P & PCSub) . self) ) // CHECK: false
193
+ print ( nongenericAnyIsPAndPCSub ( type: PE . self) ) // CHECK: false
194
+ print ( genericAnyIs ( type: PE . self, to: ( P & PCSub) . self) ) // CHECK: false
195
+ //print(nongenericAnyIsPAndPCSub(type: PC.self)) // CHECK-SR-11565: false -- FIXME: reenable this when SR-11565 is fixed
196
+ print ( genericAnyIs ( type: PC . self, to: ( P & PCSub) . self) ) // CHECK: false
197
+ print ( nongenericAnyIsPAndPCSub ( type: PCSub . self) ) // CHECK: true
198
+ print ( genericAnyIs ( type: PCSub . self, to: ( P & PCSub) . self) ) // CHECK-ONONE: true
199
+
200
+
152
201
// CHECK-LABEL: type comparisons:
153
202
print ( " type comparisons: \n " )
154
203
print ( allMetasToAllMetas ( Int . self, Int . self) ) // CHECK: true
0 commit comments