This is exactly why I think successor()/predecessor() must raise runtime error on integer overflow - because we(I believe) expect this behavior from these funcs. 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
<[email protected] <mailto:[email protected]>> 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.
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to