[SR-2371] Run-time crash in ObjC code accessing date added to NSMutableDictionary by Swift code #44978
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler itself
crash
Bug: A crash, i.e., an abnormal termination of software
run-time crash
Bug → crash: Swift code crashed during execution
Attachment: Download
Environment
Xcode 8b6
Additional Detail from JIRA
md5: 277dd98cf382487b488e4fb3c9d336e4
Issue Description:
The Swift code updates the dictionary to map a String to a Date, then attempts to pass that dictionary back to a C function, stringValueFromDictionary(), that expects an NSDictionary.
The compiler in Xcode 8b6 surfaces the C function as taking an argument of type [AnyHashable: Any], per #116. To provide the right type, we copy the NSMutableDictionary instance and cast it to [AnyHashable: Any].
In the implementation of stringValueFromDictionary(), we retrieve the date from the dictionary, expecting it to be an NSDate object. Calling any NSDate method on the value crashes.
Steps to Reproduce:
Compile and run the attached project.
Expected Results:
The bridging of the [AnyHashable: Any] value in Swift back to NSDictionary in C should bridge the Date object to NSDate.
Actual Results:
Crash:
2016-08-16 15:51:25.232 AnyWhatNow[62058:772408] -[_SwiftValue dateByAddingTimeInterval:]: unrecognized selector sent to instance 0x100d02420
2016-08-16 15:51:25.234 AnyWhatNow[62058:772408] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue dateByAddingTimeInterval:]: unrecognized selector sent to instance 0x100d02420'
(
0 CoreFoundation 0x00007fff8a6064f2 __exceptionPreprocess + 178
1 libobjc.A.dylib 0x00007fff916c8f7e objc_exception_throw + 48
2 CoreFoundation 0x00007fff8a6701ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff8a576571 _forwarding_ + 1009
4 CoreFoundation 0x00007fff8a5760f8 _CF_forwarding_prep_0 + 120
5 AnyWhatNow 0x0000000100001f5b stringValueFromDictionary + 91
6 AnyWhatNow 0x000000010000228d _TFC10AnyWhatlibc++abi.dylib: terminating with uncaught exception of type NSException
Notes:
It's entirely possible that I'm just "holding it wrong", but I've found no way to insert an date object into a dictionary in Swift and successfully make that date usable in Objective-C code that receives the dictionary.
The text was updated successfully, but these errors were encountered: