Just ran into a weird crash with Swift 2.2 in Xcode 7.3. It reproduces in a 
playground:

import Foundation
let a = [88]
let b: [Any] = a   // CRASH

In my real program, the top of the crash backtrace is:

* thread #1: tid = 0x460b62, 0x000000010669988b 
libswiftCore.dylib`swift_unknownRetain + 27, queue = 'com.apple.main-thread', 
stop reason = EXC_BAD_ACCESS (code=1, address=0x58)
    frame #0: 0x000000010669988b libswiftCore.dylib`swift_unknownRetain + 27
    frame #1: 0x0000000106488565 
libswiftCore.dylib`Swift._arrayConditionalBridgeElements <A, B> 
(Swift.Array<A>) -> Swift.Optional<Swift.Array<B>> + 1029
    frame #2: 0x00000001064875a7 libswiftCore.dylib`Swift._arrayForceCast <A, 
B> (Swift.Array<A>) -> Swift.Array<B> + 263

It’s interesting that the memory address causing the crash is 0x58, which in 
decimal is 88, the first item in the array. If you change the first item of the 
array to a different number, the crash address changes to match. So it’s 
misinterpreting the integer as a pointer.

Also interestingly, if you remove “import Foundation”, it no longer compiles — 
the last line gets an error “Cannot convert value of type ‘[Int]’ to expected 
argument type ‘[Any]’”. Is boxing of integers really dependent on Obj-C 
bridging?

—Jens

PS: Should I file the bug report with Apple or at swift.org?
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to