Skip to content

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

Closed
@einthusan

Description

@einthusan

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

bradfitz commented on Dec 31, 2014

@bradfitz
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.

changed the title [-]enum does not enforce type check under certain circumstances[/-] [+]spec: enum does not enforce type check under certain circumstances[/+] on Jan 1, 2015
locked and limited conversation to collaborators on Jun 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bradfitz@einthusan@gopherbot

        Issue actions

          spec: enum does not enforce type check under certain circumstances · Issue #9481 · golang/go