Closed
Description
Buggy Code : https://play.golang.org/p/j4kMAv2hvI
Expected : https://play.golang.org/p/UuEhvMLfr7
I am not sure if this is the expected behaviour, but if it is, can someone explain why?
It seems that if you set the value of the const
when declaring "enums", the type check breaks down. However, if you use iota
or do not set the "enum" value, it works as expected.
Activity
bradfitz commentedon Dec 31, 2014
This is by design.
See http://blog.golang.org/constants and http://golang.org/ref/spec
In your first example, E1 is an untyped constant.
You can discuss more on the golang-nuts@ mailing list.
[-]enum does not enforce type check under certain circumstances[/-][+]spec: enum does not enforce type check under certain circumstances[/+]