[SR-4555] Crash bridging objective-c dictionary when it contains NSErrors as the values #47132
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
Environment
compiled on: macOS 10.12
run on: macOS 10.12
swift version: Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
xcode 8.2.1
Additional Detail from JIRA
md5: 696d775b055c54e1feffaf4a1fcc4cfc
Issue Description:
Consider the following objective-c object:
```
NS_ASSUME_NONNULL_BEGIN
@interface BusinessObject : NSObject
@Property (nonatomic, copy, readonly) NSDictionary <NSNumber , NSError> *errorsDictionary;
@EnD
NS_ASSUME_NONNULL_END
#import "BusinessObject.h"
@implementation BusinessObject
-(NSDictionary<NSNumber *,NSError *> *)errorsDictionary{
NSError *error = [NSError errorWithDomain:@"blah" code:1234 userInfo:nil];
return @{@(1): error};
}
@EnD
```
When using this in swift like so:
```
let b = BusinessObject()
let errorsDictionary = b.errorsDictionary;
print("errorsDictionary: (errorsDictionary)")
```
you will get a crash with the following stack trace:
```
thread Redundant Load Elimination Patches #1: tid = 0x283e5d, 0x00000001002ff178 BridgeCrashWithErrorValuesInDictionaryMacOS`_swift_bridgeNonVerbatimFromObjectiveC + 248, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
frame #0: 0x00000001002ff178 BridgeCrashWithErrorValuesInDictionaryMacOS`_swift_bridgeNonVerbatimFromObjectiveC + 248
frame Redundant Load Elimination Patches #1: 0x00000001002e4270 BridgeCrashWithErrorValuesInDictionaryMacOS`deallocateBuffer value witness for Swift.LazyMapRandomAccessCollection + 16
frame Remove unnecessary
unsafeUnwrap
calls. #2: 0x00000001000b343c BridgeCrashWithErrorValuesInDictionaryMacOS`Swift._forceBridgeFromObjectiveC <A> (Swift.AnyObject, A.Type) -> A + 396frame Initial implementation of a @_cdecl attribute to export top-level functions to C #3: 0x00000001000370bd BridgeCrashWithErrorValuesInDictionaryMacOS`static (extension in Foundation):Swift.Dictionary.(unconditionallyBridgeFromObjectiveC (Swift.Optional<_ObjC.NSDictionary>) -> Swift.Dictionary<A, B>).(closure Redundant Load Elimination Patches #1) + 173
frame install Foundation via the ninja script and add the test phase for Foundation #4: 0x0000000100131fb4 BridgeCrashWithErrorValuesInDictionaryMacOS`partial apply forwarder for static (extension in Foundation):Swift.Dictionary.(unconditionallyBridgeFromObjectiveC (Swift.Optional<_ObjC.NSDictionary>) -> Swift.Dictionary<A, B>).(closure Redundant Load Elimination Patches #1) + 84
frame Only run bindings-build-record on OS X due to test flakiness on Liunx… #5: 0x0000000100031a1f BridgeCrashWithErrorValuesInDictionaryMacOS`TTRg0_Rxs8HashablerXFo_iP_iP_dGSpV10ObjectiveC8ObjCBoolXFdCb_dPs9AnyObject_dPS2dGSpS1**__ + 287
frame Debug Info: Don't reset the debug scope after leaving the outermost s… #6: 0x00007fffbd404853 CoreFoundation`-[__NSSingleEntryDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] + 67
frame Fix a bug in SILValue's hoistAddressProjections #7: 0x0000000100035c59 BridgeCrashWithErrorValuesInDictionaryMacOS`static (extension in Foundation):Swift.Dictionary.unconditionallyBridgeFromObjectiveC (Swift.Optional<_ObjC.NSDictionary>) -> Swift.Dictionary<A, B> + 617
frame Simplify configure pass for Foundation to use a defined variable for XCTest's build directory #8: 0x00000001000015b3 BridgeCrashWithErrorValuesInDictionaryMacOS`main + 307 at main.swift:14
frame update related projects list to include Foundation and XCTest #9: 0x00007fffd23c9255 libdyld.dylib`start + 1
frame Remove the FunctionEnumeration data structure from CalleeAnalysis #10: 0x00007fffd23c9255 libdyld.dylib`start + 1
```
The text was updated successfully, but these errors were encountered: