Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec: enum does not enforce type check under certain circumstances #9481

Closed
einthusan opened this issue Dec 31, 2014 · 1 comment
Closed

Comments

@einthusan
Copy link

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.

@bradfitz
Copy link
Contributor

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.

@mikioh mikioh changed the title enum does not enforce type check under certain circumstances spec: enum does not enforce type check under certain circumstances Jan 1, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants