Open swift-ci opened 8 years ago
This is correct behavior. Int(char! - 48)
evaluates the subtraction in UInt8-space, not in Int-space, and UInts can't represent negative numbers.
It would definitely be nice to get a proper error message for this, though.
Comment by Patrick Bohrer (JIRA)
I agree it was bad code but it took a while to figure out the error based on the dump/stack trace.
Comment by Patrick Bohrer (JIRA)
This was the error I got which did not help me figure out what I had done in the larger program:
Error running code:
0 swift 0x0000000002f4d598 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 swift 0x0000000002f4bd96 llvm::sys::RunSignalHandlers() + 54
2 swift 0x0000000002f4e0c6
3 libpthread.so.0 0x00007f52efaf9d10
4 libpthread.so.0 0x00007f52f0998142
5 swift 0x0000000000d0f084 llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef\<llvm::GenericValue>) + 996
6 swift 0x0000000000d1268f llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::vector\<std::*cxx11::basic_string\<char, std::char_traits\<char>, std::allocator\<char> >, std::allocator\<std::_cxx11::basic_string\<char, std::char_traits\<char>, std::allocator\<char> > > > const&, char const* const*) + 1263
7 swift 0x0000000000bedbf8 swift::RunImmediately(swift::CompilerInstance&, std::vector\<std::cxx11::basic_string\<char, std::char_traits\<char>, std::allocator\<char> >, std::allocator\<std::_cxx11::basic_string\<char, std::char_traits\<char>, std::allocator\<char> > > > const&, swift::IRGenOptions&, swift::SILOptions const&) + 2312
8 swift 0x0000000000762a98 frontend_main(llvm::ArrayRef\<char const*>, char const*, void\) + 7816
9 swift 0x000000000075cd43 main + 2835
10 libc.so.6 0x00007f52eee9ea40 __libc_start_main + 240
11 swift 0x000000000075c129 _start + 41
Stack dump:
Environment
Swift REPL. Testing on Linux for 3.0 (mar 1 & feb 25) and 2.2 (Jan 6 & 11) as well as Playground 7.3Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Standard Library | |Labels | Improvement | |Assignee | None | |Priority | Medium | md5: 12a7140ba20384c7b70ed37310ef2530Issue Description:
The following code causes an illegal instruction in the swift REPL.
Either load this code into 7.3 playground or go to the Swift Sandbox:
http://swiftlang.ng.bluemix.net/#/repl/2dde02db5d77c12fc2c8ef841e79a1679493b4e83cdde459ffcc635fc99b5e44
let char : UInt8? = 46
// This statement causes a Illegal instruction exception in the Swift REPL
let newValue = Int(char! - 48)
// However, the following works
// let newValue = Int(Int8(char!) - 48)
print (newValue)