Then enable range checking! It's disabled by default by design due to performance impact, so if you want it enable it. Then this example will crash.
Sure, if I want a crash, but often you don't want crashes but overflow. There is this disconnect that ranges that coincide with byte sizes can be used for overflow while ranges that don't can't be used like that.
And such functionality should be part of the language instead of the runtime library, because...?
1. consistency, when I define 0..255 the compiler automatically chooses a 1 byte representations. With 0..65535 it chooses 2 bytes, etc. So the compiler transparently takes a range and generates code utilizing the optimal internal representation. That's great... But why stop ant Int64? Why can't I define myself Int128 that way?
Like sure it can be provided by the runtime (and AFAIK already is) but then the question is why have ranges at all and not just define the 8 basic types (singed/unsigned into 8-64 bit) and call it a day.
Effectively this feature in pascal gives no advantage over the C integer types
2. because pascal is a high level language that has a lot of features where you write things and the compiler "makes it happen". Taking this to the extreme, why does pascal need arrays, sets, classes etc in the first place? Those can all be provided by the runtime like in C.
Again, why should it be part of the language? It being part of the runtime library makes it much easier to implement alternatives not to mention that one can implement it now.
Languages should make common things easy, you can implement sets in runtime, yet pascal has language level sets. Same for dynamic arrays or strings.
In swift you can easily write a custom map type, yet the language provides maps on language level, because its such a fundamental datatype that it warrants a special syntax.
Again those are things pascal understood in the beginning, the language was explicitly designed to abstract such things to the language level.
Pascal was a revolutionary language in the 70s-90s, but for some reason we decided to freeze and now its a very conservative language? Thats a pretty big flip in philosophy
If you'd think for a minute why variant records don't allow managed types you'd understand it... 🙄
Yes, I thought about it, I figured there is no reason why it doesn't work, and implemented it I to the FPC:
https://gitlab.com/freepascal.org/fpc/source/-/merge_requests/822It clearly can be done... So, what's the issue?
https://gitlab.com/freepascal.org/fpc/source/-/merge_requests/822It's not broken, it's just that specializing a generic establishes the scope that was active during the declaration of the
generic. The specialization can't see operator overloads (or helpers) outside the parameter types, that is
by design. (I do have plans to improve that however)
[/quote]
Sure it's not broken it's just badly designed. But haskell solved this in the 90s, so...