<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Just ran into a weird crash with Swift 2.2 in Xcode 7.3. It reproduces in a playground:<div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Consolas;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class="">import</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Foundation</span></div></div><div class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Consolas;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> a = [</span><span style="font-variant-ligatures: no-common-ligatures; color: #424242" class="">88</span><span style="font-variant-ligatures: no-common-ligatures" class="">]</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #005493" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> b: [</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Any</span><span style="font-variant-ligatures: no-common-ligatures" class="">] = </span><span style="font-variant-ligatures: no-common-ligatures; color: #80257f" class="">a &nbsp; // CRASH</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures; color: #80257f" class=""><br class=""></span></div></div></div></blockquote><div class="">In my real program, the top of the crash backtrace is:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">* thread #1: tid = 0x460b62, 0x000000010669988b libswiftCore.dylib`swift_unknownRetain + 27, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x58)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; frame #0: 0x000000010669988b libswiftCore.dylib`swift_unknownRetain + 27</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; frame #1: 0x0000000106488565 libswiftCore.dylib`Swift._arrayConditionalBridgeElements &lt;A, B&gt; (Swift.Array&lt;A&gt;) -&gt; Swift.Optional&lt;Swift.Array&lt;B&gt;&gt; + 1029</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; frame #2: 0x00000001064875a7 libswiftCore.dylib`Swift._arrayForceCast &lt;A, B&gt; (Swift.Array&lt;A&gt;) -&gt; Swift.Array&lt;B&gt; + 263</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class="">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.</div><div class=""><br class=""></div><div class="">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?</div><div class=""><br class=""></div><div class="">—Jens</div><div class=""><br class=""></div><div class="">PS: Should I file the bug report with Apple or at <a href="http://swift.org" class="">swift.org</a>?</div></body></html>