The compiler currently doesn't try the init property for global variables.
This produces the warning:
type DiceVal = range[1..6]
proc m =
var d: DiceVal
echo d
m()
Run
The check is done for the implicit variable “result” and we get the usual
warning: `Warning: Cannot prove that 'result' is initialized. This will become
a compile time error in the future. [ProveInit]`
Why not for a normal variable?
type DiceVal = range[1..6]
proc throwDic
I swear I did something like this not so long ago and Nim did complain.
No, currently this is just how default initialization is implemented. See [RFC
#252](https://github.com/nim-lang/RFCs/issues/252) and [RFC
#126](https://github.com/nim-lang/RFCs/issues/126), specifically this
[comment](https://github.com/nim-lang/RFCs/issues/126#issuecomment-615014367)
Not this is not a bug. All objects are zero-initialized upon construction.
This compiles and prints 0 :
type DiceVal = range[1..6]
var d : DiceVal
echo d # -> 0
Run
Obviously the 0-initialisation is not checked. Compiler bug?
It is a bug. I have seen a similar discussion some years ago for enums I think.
Maybe we have a needsInitialization pragma which can catch this, but I can not
find it yet.