[swift-evolution] Make integer conversion initializers failable

Félix Cloutier felixcca at yahoo.ca
Sat Feb 13 14:13:25 CST 2016


Yes, with the same intent. What would it throw, though?

Félix

> Le 13 févr. 2016 à 09:32:52, Matthew Johnson <matthew at anandabits.com> a écrit :
> 
> Are you thinking of something along the lines of is proposal?
> 
> https://github.com/apple/swift-evolution/pull/58 <https://github.com/apple/swift-evolution/pull/58>
> 
> It has been sitting as a PR for quite a while and not been merged yet. 
> 
> -Matthew
> 
>> On Feb 12, 2016, at 11:21 AM, Félix Cloutier via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> It appears that the current integer conversion initializers will either always work, possibly trap, or truncate:
>> 
>>> init(_: Int)
>>> init(_: Int8)
>>> init(_: Int16)
>>> init(_: Int32)
>>> init(_: Int64)
>>> init(_: UInt)
>>> init(_: UInt8)
>>> init(_: UInt16)
>>> init(_: UInt32)
>>> init(_: UInt64)
>>> init(truncatingBitPattern: Int)
>>> init(truncatingBitPattern: Int16)
>>> init(truncatingBitPattern: Int32)
>>> init(truncatingBitPattern: Int64)
>>> init(truncatingBitPattern: UInt)
>>> init(truncatingBitPattern: UInt16)
>>> init(truncatingBitPattern: UInt32)
>>> init(truncatingBitPattern: UInt64)
>> 
>> I suggest that we change trapping initializers to failable initializers. Initializers that can't fail (identity, unsigned -> bigger signed/unsigned, signed -> bigger signed) should keep a non-Optional type.
>> 
>> This could extend to changing SignedIntegerType's and UnsignedIntegerType's (U)IntMax to failable initializers as well.
>> 
>> I think I remember someone on the core team saying that someone's working on integer types at the moment. Is that right?
>> 
>> Félix
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160213/8be710cc/attachment.html>


More information about the swift-evolution mailing list