This compiles and prints 0 :
type DiceVal = range[1..6]
var d : DiceVal
echo d # -> 0
Obviously the 0-initialisation is not checked. Compiler bug?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 throwDice(): DiceVal =
discard
echo throwDice()
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()