swift icon indicating copy to clipboard operation
swift copied to clipboard

[SR-348] [String] cannot bridge to [Any]

Open tkremenek opened this issue 10 years ago • 1 comments

Previous ID SR-348
Radar None
Original Reporter @tkremenek
Type Bug
Status Resolved
Resolution Done

Environment

Host OS: OS X 10.11
Swift.org snapshot: swift-2.2-SNAPSHOT-2015-12-18-a

Additional Detail from JIRA
Votes 2
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: f37ed5f677b08282ee714f518b1a87e2

relates to:

  • SR-274 Upcasting construction of Array from Set is going through bridging (and failing)

Issue Description:

The following code compiles but fails to run:

main.swift

import Foundation
let strArray = [ "a", "b", "c" ]
func takesAnyArray(array: [Any]) {}

// fatal error: can't unsafeBitCast between types of different sizes
takesAnyArray(strArray)

The bridging between `Array<String>` and `Array<Any>` depends on runtime functionality that is not working.

Stack trace:

fatal error: can't unsafeBitCast between types of different sizes
0  swift                    0x00000001099f9a0b llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1  swift                    0x00000001099f8cc6 llvm::sys::RunSignalHandlers() + 70
2  swift                    0x00000001099fa0b2 SignalHandler(int) + 322
3  libsystem_platform.dylib 0x00007fff9b0ef2ca _sigtramp + 26
4  libsystem_platform.dylib 0x00007fff616d78d8 _sigtramp + 3328083496
5  libswiftCore.dylib       0x000000010dc46a72 _TFs31_arrayConditionalBridgeElementsu0_rFGSax_GSqGSaq___ + 1970
6  libswiftCore.dylib       0x000000010dc45247 _TFs15_arrayForceCastu0_rFGSax_GSaq__ + 263
7  libswiftCore.dylib       0x000000010bde8135 _TFs15_arrayForceCastu0_rFGSax_GSaq__ + 4263129077
8  swift                    0x00000001078ec461 llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 1345
9  swift                    0x00000001078ef7cf llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, char const* const*) + 1231
10 swift                    0x00000001077b7e30 swift::RunImmediately(swift::CompilerInstance&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, swift::IRGenOptions&, swift::SILOptions const&) + 2752
11 swift                    0x00000001072ca333 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 15187
12 swift                    0x00000001072c5bda frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2794
13 swift                    0x00000001072c11a7 main + 2855
14 libdyld.dylib            0x00007fff9aed7489 start + 1
15 libdyld.dylib            0x000000000000000c start + 1695714180

tkremenek avatar Dec 22 '15 23:12 tkremenek

The provided example runs fine in Xcode 9.4.1 toolchain, probably also much earlier as well.

Dante-Broggi avatar Jul 16 '18 05:07 Dante-Broggi