Hi.
Why do I receive a warning? I can not use positive numbers?
var t: range[5..10] # Warning: Cannot prove that 't' is initialized. This will become a compile time error in the future. [ProveInit]
var t: range[0..10] # no warning
var t: range[-1..10] # no warning
var t: range[-5..10] # no warning
It's quite simple actually. By default, all Nim variables are initialized to binary zero. For all of these ranges but for the first one, binary zero (which is numeric zero as well) is a valid value. But that's not the case for the first range sooo... The compiler complains that it can't prove the variable will ever have a valid value (because binary zero is not a valid value for this type).
If you're sure you will initialize this variable elsewhere, use {.noInit} pragma. If not, you really should set it, just like the compiler suggests you.
Simple, but I did not quite understand. I want something like this.
var t: range['a'..'z'] # Warning: Cannot prove that 't' is initialized. This will become a compile time error in the future. [ProveInit]
t = 'c'
echo t
What am I doing wrong?What am I doing wrong?
answer: nothing wrong
but initializing t to zero (0) by default fails, because zero is not in the range 'a'.. 'z'
So you would need to do
var t: range['a'..'z'] = 'c'
HOWEVER the warning still issues when itialized. This is I assume a bug ;-) (which I will log as an issue)
Edit: Issue 6474