[swift-users] Assigning [Int] to [Any] crashes Swift 2.2

Jens Alfke jens at mooseyard.com
Wed Apr 13 23:09:59 CDT 2016


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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160413/da59e678/attachment.html>


More information about the swift-users mailing list