@@ -141,170 +141,175 @@ DictionaryTraps.test("BridgedKeyIsNotNSCopyable2")
141
141
nsd. mutableCopy ( )
142
142
}
143
143
144
- DictionaryTraps . test ( " ForcedNonverbatimBridge.StringKey " )
144
+ if #available( macOS 15 , iOS 13 , watchOS 6 , tvOS 13 , * ) {
145
+ // The behavior tested here was introduced in
146
+ // https://github.com/apple/swift/pull/23174
147
+
148
+ DictionaryTraps . test ( " ForcedNonverbatimBridge.StringKey " )
145
149
. skip ( . custom(
146
- { _isFastAssertConfiguration ( ) } ,
147
- reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
150
+ { _isFastAssertConfiguration ( ) } ,
151
+ reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
148
152
. crashOutputMatches ( " Could not cast value of type " )
149
153
. code {
150
- let d1 : NSDictionary = [
151
- " Gordon " as NSString : NSObject ( ) ,
152
- " William " as NSString : NSObject ( ) ,
153
- " Katherine " as NSString : NSObject ( ) ,
154
- " Lynn " as NSString : NSObject ( ) ,
155
- " Brian " as NSString : NSObject ( ) ,
156
- 1756 as NSNumber : NSObject ( ) ]
157
-
158
- expectCrashLater ( )
159
- _ = d1 as! Dictionary < String , Any >
160
- }
154
+ let d1 : NSDictionary = [
155
+ " Gordon " as NSString : NSObject ( ) ,
156
+ " William " as NSString : NSObject ( ) ,
157
+ " Katherine " as NSString : NSObject ( ) ,
158
+ " Lynn " as NSString : NSObject ( ) ,
159
+ " Brian " as NSString : NSObject ( ) ,
160
+ 1756 as NSNumber : NSObject ( ) ]
161
+
162
+ expectCrashLater ( )
163
+ _ = d1 as! Dictionary < String , Any >
164
+ }
161
165
162
- DictionaryTraps . test ( " ForcedNonverbatimBridge.IntKey " )
166
+ DictionaryTraps . test ( " ForcedNonverbatimBridge.IntKey " )
163
167
. skip ( . custom(
164
- { _isFastAssertConfiguration ( ) } ,
165
- reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
168
+ { _isFastAssertConfiguration ( ) } ,
169
+ reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
166
170
. crashOutputMatches ( " Could not cast value of type " )
167
171
. code {
168
172
169
- let d1 : NSDictionary = [
170
- 4 as NSNumber : NSObject ( ) ,
171
- 8 as NSNumber : NSObject ( ) ,
172
- 15 as NSNumber : NSObject ( ) ,
173
- 16 as NSNumber : NSObject ( ) ,
174
- 23 as NSNumber : NSObject ( ) ,
175
- 42 as NSNumber : NSObject ( ) ,
176
- " John " as NSString : NSObject ( ) ]
177
-
178
- expectCrashLater ( )
179
- _ = d1 as! Dictionary < Int , Any >
180
- }
173
+ let d1 : NSDictionary = [
174
+ 4 as NSNumber : NSObject ( ) ,
175
+ 8 as NSNumber : NSObject ( ) ,
176
+ 15 as NSNumber : NSObject ( ) ,
177
+ 16 as NSNumber : NSObject ( ) ,
178
+ 23 as NSNumber : NSObject ( ) ,
179
+ 42 as NSNumber : NSObject ( ) ,
180
+ " John " as NSString : NSObject ( ) ]
181
+
182
+ expectCrashLater ( )
183
+ _ = d1 as! Dictionary < Int , Any >
184
+ }
181
185
182
- DictionaryTraps . test ( " ForcedNonverbatimBridge.Value " )
186
+ DictionaryTraps . test ( " ForcedNonverbatimBridge.Value " )
183
187
. skip ( . custom(
184
- { _isFastAssertConfiguration ( ) } ,
185
- reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
188
+ { _isFastAssertConfiguration ( ) } ,
189
+ reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
186
190
. crashOutputMatches ( " Could not cast value of type " )
187
191
. code {
188
192
189
- let d1 : NSDictionary = [
190
- 4 as NSNumber : " Jack " as NSString ,
191
- 8 as NSNumber : " Kate " as NSString ,
192
- 15 as NSNumber : " Hurley " as NSString ,
193
- 16 as NSNumber : " Sawyer " as NSString ,
194
- 23 as NSNumber : " John " as NSString ,
195
- 42 as NSNumber : NSObject ( ) ]
193
+ let d1 : NSDictionary = [
194
+ 4 as NSNumber : " Jack " as NSString ,
195
+ 8 as NSNumber : " Kate " as NSString ,
196
+ 15 as NSNumber : " Hurley " as NSString ,
197
+ 16 as NSNumber : " Sawyer " as NSString ,
198
+ 23 as NSNumber : " John " as NSString ,
199
+ 42 as NSNumber : NSObject ( ) ]
196
200
197
- expectCrashLater ( )
198
- _ = d1 as! Dictionary < NSObject , String >
199
- }
201
+ expectCrashLater ( )
202
+ _ = d1 as! Dictionary < NSObject , String >
203
+ }
200
204
201
- DictionaryTraps . test ( " ForcedVerbatimBridge.StringKey " )
205
+ DictionaryTraps . test ( " ForcedVerbatimBridge.StringKey " )
202
206
. skip ( . custom(
203
- { _isFastAssertConfiguration ( ) } ,
204
- reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
207
+ { _isFastAssertConfiguration ( ) } ,
208
+ reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
205
209
. crashOutputMatches ( " Could not cast value of type " )
206
210
. code {
207
- let d1 : NSDictionary = [
208
- " Gordon " as NSString : NSObject ( ) ,
209
- " William " as NSString : NSObject ( ) ,
210
- " Katherine " as NSString : NSObject ( ) ,
211
- " Lynn " as NSString : NSObject ( ) ,
212
- " Brian " as NSString : NSObject ( ) ,
213
- 1756 as NSNumber : NSObject ( ) ]
214
-
215
- // With the ObjC runtime, the verbatim downcast is O(1); it performs no
216
- // runtime checks.
217
- let d2 = d1 as! Dictionary < NSString , NSObject >
218
- // Element access goes through the bridged path and performs forced downcasts.
219
- // This is where the odd numeric value is caught.
220
- expectCrashLater ( )
221
- for (key, value) in d2 {
222
- _ = ( key, value)
211
+ let d1 : NSDictionary = [
212
+ " Gordon " as NSString : NSObject ( ) ,
213
+ " William " as NSString : NSObject ( ) ,
214
+ " Katherine " as NSString : NSObject ( ) ,
215
+ " Lynn " as NSString : NSObject ( ) ,
216
+ " Brian " as NSString : NSObject ( ) ,
217
+ 1756 as NSNumber : NSObject ( ) ]
218
+
219
+ // With the ObjC runtime, the verbatim downcast is O(1); it performs no
220
+ // runtime checks.
221
+ let d2 = d1 as! Dictionary < NSString , NSObject >
222
+ // Element access goes through the bridged path and performs forced downcasts.
223
+ // This is where the odd numeric value is caught.
224
+ expectCrashLater ( )
225
+ for (key, value) in d2 {
226
+ _ = ( key, value)
227
+ }
223
228
}
224
- }
225
229
226
- DictionaryTraps . test ( " ForcedVerbatimBridge.IntKey " )
230
+ DictionaryTraps . test ( " ForcedVerbatimBridge.IntKey " )
227
231
. skip ( . custom(
228
- { _isFastAssertConfiguration ( ) } ,
229
- reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
232
+ { _isFastAssertConfiguration ( ) } ,
233
+ reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
230
234
. crashOutputMatches ( " Could not cast value of type " )
231
235
. code {
232
236
233
- let d1 : NSDictionary = [
234
- 4 as NSNumber : NSObject ( ) ,
235
- 8 as NSNumber : NSObject ( ) ,
236
- 15 as NSNumber : NSObject ( ) ,
237
- 16 as NSNumber : NSObject ( ) ,
238
- 23 as NSNumber : NSObject ( ) ,
239
- 42 as NSNumber : NSObject ( ) ,
240
- " John " as NSString : NSObject ( ) ]
241
-
242
- // With the ObjC runtime, the verbatim downcast is O(1); it performs no
243
- // runtime checks.
244
- let d2 = d1 as! Dictionary < NSNumber , NSObject >
245
- // Element access goes through the bridged path and performs forced downcasts.
246
- // This is where the odd numeric value is caught.
247
- expectCrashLater ( )
248
- for (key, value) in d2 {
249
- _ = ( key, value)
237
+ let d1 : NSDictionary = [
238
+ 4 as NSNumber : NSObject ( ) ,
239
+ 8 as NSNumber : NSObject ( ) ,
240
+ 15 as NSNumber : NSObject ( ) ,
241
+ 16 as NSNumber : NSObject ( ) ,
242
+ 23 as NSNumber : NSObject ( ) ,
243
+ 42 as NSNumber : NSObject ( ) ,
244
+ " John " as NSString : NSObject ( ) ]
245
+
246
+ // With the ObjC runtime, the verbatim downcast is O(1); it performs no
247
+ // runtime checks.
248
+ let d2 = d1 as! Dictionary < NSNumber , NSObject >
249
+ // Element access goes through the bridged path and performs forced downcasts.
250
+ // This is where the odd numeric value is caught.
251
+ expectCrashLater ( )
252
+ for (key, value) in d2 {
253
+ _ = ( key, value)
254
+ }
250
255
}
251
- }
252
256
253
- DictionaryTraps . test ( " ForcedVerbatimBridge.Value " )
257
+ DictionaryTraps . test ( " ForcedVerbatimBridge.Value " )
254
258
. skip ( . custom(
255
- { _isFastAssertConfiguration ( ) } ,
256
- reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
259
+ { _isFastAssertConfiguration ( ) } ,
260
+ reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
257
261
. crashOutputMatches ( " Could not cast value of type " )
258
262
. code {
259
263
260
- let d1 : NSDictionary = [
261
- 4 as NSNumber : " Jack " as NSString ,
262
- 8 as NSNumber : " Kate " as NSString ,
263
- 15 as NSNumber : " Hurley " as NSString ,
264
- 16 as NSNumber : " Sawyer " as NSString ,
265
- 23 as NSNumber : " John " as NSString ,
266
- 42 as NSNumber : NSObject ( ) ]
267
-
268
- // With the ObjC runtime, the verbatim downcast is O(1); it performs no
269
- // runtime checks.
270
- let d2 = d1 as! Dictionary < NSObject , NSString >
271
- // Element access goes through the bridged path and performs forced downcasts.
272
- // This is where the odd numeric value is caught.
273
- expectCrashLater ( )
274
- for (key, value) in d2 {
275
- _ = ( key, value)
264
+ let d1 : NSDictionary = [
265
+ 4 as NSNumber : " Jack " as NSString ,
266
+ 8 as NSNumber : " Kate " as NSString ,
267
+ 15 as NSNumber : " Hurley " as NSString ,
268
+ 16 as NSNumber : " Sawyer " as NSString ,
269
+ 23 as NSNumber : " John " as NSString ,
270
+ 42 as NSNumber : NSObject ( ) ]
271
+
272
+ // With the ObjC runtime, the verbatim downcast is O(1); it performs no
273
+ // runtime checks.
274
+ let d2 = d1 as! Dictionary < NSObject , NSString >
275
+ // Element access goes through the bridged path and performs forced downcasts.
276
+ // This is where the odd numeric value is caught.
277
+ expectCrashLater ( )
278
+ for (key, value) in d2 {
279
+ _ = ( key, value)
280
+ }
276
281
}
277
- }
278
282
279
- DictionaryTraps . test ( " Downcast.Verbatim " )
283
+ DictionaryTraps . test ( " Downcast.Verbatim " )
280
284
. skip ( . custom(
281
- { _isFastAssertConfiguration ( ) } ,
282
- reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
285
+ { _isFastAssertConfiguration ( ) } ,
286
+ reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
283
287
. crashOutputMatches ( " Could not cast value of type " )
284
288
. code {
285
- let d : Dictionary < NSObject , NSObject > = [ TestObjCKeyTy ( 10 ) : NSObject ( ) ,
286
- NSObject ( ) : NSObject ( ) ]
287
- let d2 : Dictionary < TestObjCKeyTy , NSObject > = _dictionaryDownCast ( d)
288
- expectCrashLater ( )
289
- _ = d2 [ TestObjCKeyTy ( 10 ) ]
290
- _ = d2 [ TestObjCKeyTy ( 20 ) ]
291
-
292
- // This triggers failure.
293
- for (_, _) in d2 { }
294
- }
289
+ let d : Dictionary < NSObject , NSObject > = [ TestObjCKeyTy ( 10 ) : NSObject ( ) ,
290
+ NSObject ( ) : NSObject ( ) ]
291
+ let d2 : Dictionary < TestObjCKeyTy , NSObject > = _dictionaryDownCast ( d)
292
+ expectCrashLater ( )
293
+ _ = d2 [ TestObjCKeyTy ( 10 ) ]
294
+ _ = d2 [ TestObjCKeyTy ( 20 ) ]
295
+
296
+ // This triggers failure.
297
+ for (_, _) in d2 { }
298
+ }
295
299
296
- DictionaryTraps . test ( " Downcast.NonVerbatimBridged " )
300
+ DictionaryTraps . test ( " Downcast.NonVerbatimBridged " )
297
301
. skip ( . custom(
298
- { _isFastAssertConfiguration ( ) } ,
299
- reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
302
+ { _isFastAssertConfiguration ( ) } ,
303
+ reason: " this trap is not guaranteed to happen in -Ounchecked " ) )
300
304
. crashOutputMatches ( " Could not cast value of type " )
301
305
. code {
302
- let d : Dictionary < NSObject , NSObject > = [ TestObjCKeyTy ( 10 ) : NSObject ( ) ,
303
- NSObject ( ) : NSObject ( ) ]
306
+ let d : Dictionary < NSObject , NSObject > = [ TestObjCKeyTy ( 10 ) : NSObject ( ) ,
307
+ NSObject ( ) : NSObject ( ) ]
304
308
305
- expectCrashLater ( )
306
- let d2 = d as! Dictionary < TestBridgedKeyTy , NSObject >
307
- _ = d2 [ TestBridgedKeyTy ( 10 ) ]
309
+ expectCrashLater ( )
310
+ let d2 = d as! Dictionary < TestBridgedKeyTy , NSObject >
311
+ _ = d2 [ TestBridgedKeyTy ( 10 ) ]
312
+ }
308
313
}
309
314
310
315
runAllTests ( )
0 commit comments