[SR-7145] Dictionary.Values does not satisfy MutableCollection requirements #49693
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
standard library
Area: Standard library umbrella
Environment
Swift 4.1
Swift 4.2
Additional Detail from JIRA
md5: 4e2e499f88977c2bd588f64fee40342d
Issue Description:
For Dictionaries bridged over from Objective-C, Dictionary.Values does not correctly implement MutableCollection.
MutableCollection has the semantic requirement that the subscript setter must not invalidate indices. However, the Dictionary.Values.subscript setter converts to native storage, which invalidates existing (Cocoa) indices as a side effect:
import Foundation
let d = NSDictionary(dictionary: ["Hello": 1, "World": 2]) as Dictionary
let i = d.index(forKey: "Hello" as NSString)!
var values = d.values
values[i] = 42 as NSNumber
print(values[i]) // Traps, invalid index
The text was updated successfully, but these errors were encountered: