Subrange check during initialisation

2020-10-29 Thread Araq
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

Subrange check during initialisation

2020-10-29 Thread lscrd
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

Subrange check during initialisation

2020-10-29 Thread xigoi
I swear I did something like this not so long ago and Nim did complain.

Subrange check during initialisation

2020-10-29 Thread haxscramper_
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)

Subrange check during initialisation

2020-10-29 Thread haxscramper_
Not this is not a bug. All objects are zero-initialized upon construction.

Subrange check during initialisation

2020-10-29 Thread michy
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?

Subrange check during initialisation

2020-10-29 Thread Stefan_Salewski
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.