File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed
stdlib/public/Darwin/Foundation Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -500,7 +500,10 @@ fileprivate struct _JSONKeyedEncodingContainer<K : CodingKey> : KeyedEncodingCon
500
500
501
501
public mutating func nestedContainer< NestedKey> ( keyedBy keyType: NestedKey . Type , forKey key: Key ) -> KeyedEncodingContainer < NestedKey > {
502
502
let containerKey = _converted ( key) . stringValue
503
- let dictionary = self . container [ containerKey] as? NSMutableDictionary ?? NSMutableDictionary ( )
503
+ let existingContainer = self . container [ containerKey]
504
+ precondition ( existingContainer is NSMutableDictionary ? ,
505
+ " Attempt to request for keyed container with the key that previously unkeyed container already requested. " )
506
+ let dictionary = existingContainer as? NSMutableDictionary ?? NSMutableDictionary ( )
504
507
self . container [ containerKey] = dictionary
505
508
506
509
self . codingPath. append ( key)
@@ -512,7 +515,10 @@ fileprivate struct _JSONKeyedEncodingContainer<K : CodingKey> : KeyedEncodingCon
512
515
513
516
public mutating func nestedUnkeyedContainer( forKey key: Key ) -> UnkeyedEncodingContainer {
514
517
let containerKey = _converted ( key) . stringValue
515
- let array = self . container [ containerKey] as? NSMutableArray ?? NSMutableArray ( )
518
+ let existingContainer = self . container [ containerKey]
519
+ precondition ( existingContainer is NSMutableArray ? ,
520
+ " Attempt to request for unkeyed container with the key that previously keyed container already requested. " )
521
+ let array = existingContainer as? NSMutableArray ?? NSMutableArray ( )
516
522
self . container [ containerKey] = array
517
523
518
524
self . codingPath. append ( key)
Original file line number Diff line number Diff line change @@ -266,7 +266,10 @@ fileprivate struct _PlistKeyedEncodingContainer<K : CodingKey> : KeyedEncodingCo
266
266
267
267
public mutating func nestedContainer< NestedKey> ( keyedBy keyType: NestedKey . Type , forKey key: Key ) -> KeyedEncodingContainer < NestedKey > {
268
268
let containerKey = key. stringValue
269
- let dictionary = self . container [ containerKey] as? NSMutableDictionary ?? NSMutableDictionary ( )
269
+ let existingContainer = self . container [ containerKey]
270
+ precondition ( existingContainer is NSMutableDictionary ? ,
271
+ " Attempt to request for keyed container with the key that previously unkeyed container already requested. " )
272
+ let dictionary = existingContainer as? NSMutableDictionary ?? NSMutableDictionary ( )
270
273
self . container [ containerKey] = dictionary
271
274
272
275
self . codingPath. append ( key)
@@ -278,7 +281,10 @@ fileprivate struct _PlistKeyedEncodingContainer<K : CodingKey> : KeyedEncodingCo
278
281
279
282
public mutating func nestedUnkeyedContainer( forKey key: Key ) -> UnkeyedEncodingContainer {
280
283
let containerKey = key. stringValue
281
- let array = self . container [ containerKey] as? NSMutableArray ?? NSMutableArray ( )
284
+ let existingContainer = self . container [ containerKey]
285
+ precondition ( existingContainer is NSMutableArray ? ,
286
+ " Attempt to request for unkeyed container with the key that previously keyed container already requested. " )
287
+ let array = existingContainer as? NSMutableArray ?? NSMutableArray ( )
282
288
self . container [ containerKey] = array
283
289
284
290
self . codingPath. append ( key)
You can’t perform that action at this time.
0 commit comments