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: clarify meaning of alias decls in sequence of "enum" const declaration #17784

griesemer opened this issue Nov 3, 2016 · 6 comments


Copy link

package main

import "math"
import "fmt"

const (
	a = iota
	c => math.Pi

func main() {
	fmt.Println(a, b, c, d)


0 1 3.141592653589793 2

It probably shouldn't be allowed in the first place. Certainly the output is wrong (iota should be incremented with each semicolon).

@griesemer griesemer self-assigned this Nov 3, 2016
@griesemer griesemer added this to the Go1.8 milestone Nov 3, 2016
Copy link

CL mentions this issue.

Copy link

mdempsky commented Nov 3, 2016

Certainly the output is wrong (iota should be incremented with each semicolon).

Currently the spec says iota's value increments after each ConstSpec, and AliasSpec is disjoint from ConstSpec. So I think replacing "d" with "d = iota" would logically assign 2 to d, under the current wording.

That said, if we did want to change it to increment at semicolons, I'm not opposed to that. I just expect in practice it won't really matter. If we choose to increment only after ConstSpecs, users can still include blank ConstSpecs next to AliasSpecs to increment iota; conversely, they can move AliasSpecs out-of-line to prevent them from incrementing iota.

Copy link

I agree with Matthew that the current interpretation is clear, and that it matters little in practice. I also think the current interpretation is defensible: iota shouldn't increment after an alias declaration that can't possibly use it.

Copy link
Contributor Author

@mdempsky, @alandonovan Good point - with the current spec, incrementing iota with each ConstSpec is the same as incrementing with each semicolon...

There's a simpler solution: Do not alias const aliases in the first place. Just something to keep in mind.

Copy link

If you replace => with = it prints

0 1 3.141592653589793 3.141592653589793 ( )

Since => and = are essentially the same for consts, I'd expect them to behave identically.

Copy link

rsc commented Nov 27, 2016

Locking because aliases are no longer proposed.

@golang golang locked and limited conversation to collaborators Nov 27, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
None yet

No branches or pull requests

6 participants