diff --git a/Foundation/NSDictionary.swift b/Foundation/NSDictionary.swift index 18392f49d8..db0e8d6f66 100644 --- a/Foundation/NSDictionary.swift +++ b/Foundation/NSDictionary.swift @@ -586,7 +586,7 @@ open class NSMutableDictionary : NSDictionary { guard type(of: self) === NSDictionary.self || type(of: self) === NSMutableDictionary.self else { NSRequiresConcreteImplementation() } - _storage[(aKey as! NSObject)] = _SwiftValue.store(anObject) + _storage[_SwiftValue.store(aKey)] = _SwiftValue.store(anObject) } public convenience required init() { diff --git a/TestFoundation/TestNSDictionary.swift b/TestFoundation/TestNSDictionary.swift index b1435d4565..a5380de256 100644 --- a/TestFoundation/TestNSDictionary.swift +++ b/TestFoundation/TestNSDictionary.swift @@ -32,6 +32,7 @@ class TestNSDictionary : XCTestCase { ("test_mutableCopying", test_mutableCopying), ("test_writeToFile", test_writeToFile), ("test_initWithContentsOfFile", test_initWithContentsOfFile), + ("test_settingWithStringKey", test_settingWithStringKey), ] } @@ -222,6 +223,12 @@ class TestNSDictionary : XCTestCase { } } + func test_settingWithStringKey() { + let dict = NSMutableDictionary() + // has crashed in the past + dict["stringKey"] = "value" + } + private func createTestFile(_ path: String, _contents: Data) -> String? { let tempDir = NSTemporaryDirectory() + "TestFoundation_Playground_" + NSUUID().uuidString + "/" do {