Skip to content

[4.1] Fix for when key is a String rather than NSString. #1448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Foundation/NSDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 7 additions & 0 deletions TestFoundation/TestNSDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class TestNSDictionary : XCTestCase {
("test_mutableCopying", test_mutableCopying),
("test_writeToFile", test_writeToFile),
("test_initWithContentsOfFile", test_initWithContentsOfFile),
("test_settingWithStringKey", test_settingWithStringKey),
]
}

Expand Down Expand Up @@ -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 {
Expand Down