You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
range is a type that currently is best avoided due to the large number of bugs, semantic gaps and inconsistencies it has with respect to the rest of the language.
Removing it is hard, but we can at least start plugging some of the gaps with warnings, starting with the most obvious one, where "non-overlapping" range conversion implicitly triggers runtime panics, a significant footgun compared to other similar conversions that have to be made explicit (ie assigning an int to an int8):
typeFakeUint8=range[0..255]
typeOffByOneRange=range[1..256]
var v: FakeUint8var x =256var y =OffByOneRange(256)
v = x # panics, should trigger warning
v =FakeUint8(x) # panics, should not trigger warning
v = y # panics should trigger warningprocxxx(v: FakeUint8)=discardxxx(x) # panics, should trigger warningxxx(FakeUint8(x)) # panics, should not trigger warning
The above strategy would model range in line with other "integer size" conversions where converting to a "bigger" range is allowed implicitly while converting to a smaller range requires explicit action.
In this world, an int is obviously a special case of range[int.low..int.high], int16 is naturally a range[int16.low..int16.high] and so on, which would help guide a sound strategy for all integer sizes, now and in the future..
Nim Version
2.2
Current Output
Expected Output
Known Workarounds
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered:
Description
range
is a type that currently is best avoided due to the large number of bugs, semantic gaps and inconsistencies it has with respect to the rest of the language.Removing it is hard, but we can at least start plugging some of the gaps with warnings, starting with the most obvious one, where "non-overlapping" range conversion implicitly triggers runtime panics, a significant footgun compared to other similar conversions that have to be made explicit (ie assigning an int to an int8):
The above strategy would model
range
in line with other "integer size" conversions where converting to a "bigger" range is allowed implicitly while converting to a smaller range requires explicit action.In this world, an
int
is obviously a special case ofrange[int.low..int.high]
,int16
is naturally arange[int16.low..int16.high]
and so on, which would help guide a sound strategy for all integer sizes, now and in the future..Nim Version
2.2
Current Output
Expected Output
Known Workarounds
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: