Hi there.
I'm using the latest Nimrod version off of Github.
I saw this behavior in the official 0.9.6 which I've been using so far, but also wanted to check the latest Github version before asking this.
So, I have a file test.nim in a clean directory, with these contents:
type
TSubrange = range[0..5]
var
x: TSubrange
x = 5
echo x
x += 5
echo x
And then I compile and run it like this:
nimrod c -r --verbosity:0 test.nim
Then I get this output:
5
10
Why does 10 get printed there, rather than a range-checking runtime exception being raised on the "x += 5" line?
Also get the same output when I explicitly enable the range-checking option:
nimrod c -r --verbosity:0 --rangeChecks:on test.nim
Hi Araq, thanks for the reply.
I see in the bug tracker report:
"This is hard to fix because the iterators for enums rely on this behaviour."
I don't know a thing about how the compiler works, but maybe it's possible to start deprecating that behavior?
eg - a later Nimrod version starts logging warnings when compiled in regular debug-friendly/non-release mode (even if - eg - it doesn't raise an actual exception) - which can then be suppressed by using a pragma saying "I know what I'm doing here".
Then in a follow-up Nimrod release, those runtime checks get enabled everywhere (at least in debug-friendly/non-release compiled mode) where the "I know what I'm doing" pragma isn't used.
but maybe it's possible to start deprecating that behavior?
Well my comment is misleading, it's not hard to fix, but more grunt work than I would like. ;-)