On Sun, Aug 9, 2020, 12:07 AM Steven D'Aprano
[*] For languages with bounded data types, this is more compelling. If
I think a variable will *definitely* fit in a uint8, having the static tool tell me it might not is powerful.
uint8 = int[0:256]
So if it's useful to know that something might violate the type uint8, surely it is just as useful to know that it might violate the range int[0:256].
These seem like VERY different concerns. There's nothing all that special about 255 per se, most of the time. My actual expectation might be that I'll store a Natural number roughly under 50, for example. But 51 isn't per se an error. Maybe this is the usage of a limited, but somewhat elastic resource; using 256 things might be terrible performance, but it's not logically wrong.
With a uint8 in a language that has that, we get suddenly different behavior with 255+1, versus 254+1. Either it wraps around to zero in C11, or it raises an exception in a guarded language.