[swift-evolution] Improvement proposal: change overflow behavior in successor()/predecessor() methods for Int types
svabox at gmail.com
Thu Apr 7 12:32:17 CDT 2016
This is exactly why I think successor()/predecessor() must raise runtime
error on integer overflow - because we(I believe) expect this behavior from
For example, someone, who don't know about current behavior of these
methods, can use them to increment/decrement index for some
collection/array and so produce hard-to-find errors or vulnerable code.
Any other opinion on this proposal please?
On 07.04.2016 14:31, Haravikk wrote:
>> On 7 Apr 2016, at 08:20, Vladimir.S via swift-evolution
>> <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> (TLDR: Suggest to change successor() method for Int values to follow
>> default Swift rules for integer overflow. Probably some kind of
>> successorWithOverflow could be introduced to use when needed)
> I’m a +1 for this; in fact, this is just how I assumed they worked, as the
> postcondition requirement for .successor() is that n.successor() > n if I
> remember right, which clearly can’t be the case if the limit of the integer
> is reached, so a runtime error seems reasonable.
More information about the swift-evolution