This is correct behavior. The converting (unlabeled) initializer for integers always traps if the value to convert is out of bounds. Use init(truncating:) if you want C-like behavior.
Thanks Jordan.
I understand that and it's a good idea to throw an error on an attempt at a conversion which leads to loss of data, but perhaps “Illegal instruction” isn’t a good description for it...
For example attempting to initialise the same UInt from a integer literal shows a much better error message
varp = UInt(0x1234567890ABCDEF)
error: integer literal '1311768467294899695' overflows when stored into 'Int'
Environment
Swift version 3.0-dev (LLVM e6ce0a6282, Clang 4ca9e01a7c, Swift b906a25)
Target: armv7--linux-gnueabihf
Additional Detail from JIRA
md5: 2a13ba44941fd11781b937d55d57c98d
Issue Description:
Code that relies on conversion from UInt64 to UInt or UInt32 is crashing at run-time on 32bit ARM (armv7) with an error of Illegal instruction.
One example where such code is used is the Swift Package Manager.
The code below replicates the issue:
In this case the UInt(u64sample) step causes the run-time crash
The text was updated successfully, but these errors were encountered: