Unsure what I should be doing differently in the following code as to prevent the warnings:
import strutils
type MouseButton* = enum
mbLeft = 1
mbMiddle = 2
mbRight = 3
let s = "mbLeft"
let m = parseEnum[MouseButton](s)
echo m
Warnings:
test.nim(9, 18) template/generic instantiation from here
lib/pure/strutils.nim(994, 3) Warning: Cannot prove that 'result' is initialized. This will become a compile time error in the future. [ProveInit]
test.nim(9, 5) Warning: Cannot prove that 'm' is initialized. This will become a compile time error in the future. [ProveInit]
Any suggestions would be appreciated, thanks!
You can avoid the warning by having the enum start at 0:
type MouseButton* = enum
mbNone
mbLeft = 1
mbMiddle = 2
mbRight = 3
Since enum default to the value 0, and your enum starts at 1, the default value of your enum is invalid:
type MouseButton* = enum
mbLeft = 1
mbMiddle = 2
var ml : MouseButton
echo ml #> 0 (invalid data!)
Actually, I think that you can make it start from whatever value you want, eg. -23, as long as your enum contains a value for 0, but I haven't tested it.
(note that even if you start from a negative number, the default value of the enum is the one that corresponds to 0, not the first one in the list)