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

cmd/compile: iota inside function in a ConstSpec is not accepted #22344

griesemer opened this issue Oct 19, 2017 · 4 comments


None yet
3 participants
Copy link

commented Oct 19, 2017 reports an error, but the spec doesn't prohibit this code. is accepted, and there is no reason why the former, with iota being declared in the universe block shouldn't also be accepted within the constant declaration.


This comment has been minimized.

Copy link
Contributor Author

commented Oct 19, 2017

Not urgent in any way but marked as 1.10 so it doesn't slip from the radar. Might be an easy fix.


This comment has been minimized.

Copy link

commented Oct 20, 2017

There is a paradox

package main

import "unsafe"

const (
	i = 1
	x = unsafe.Sizeof(func() {const a = iota; var _ [a-2]int }) // a is 0 or 3?

func main() {

The current gc thinks a is 0.


This comment has been minimized.

Copy link

commented Oct 20, 2017

const a = iota sets a to 0.


This comment has been minimized.

Copy link
Contributor Author

commented Oct 20, 2017

@go101 This "paradox" was addressed with the most recent changes for #15550. The value of iota is the index of the respective ConstSpec in the constant declaration. Here you have a constant declaration inside the function, and the iota is in the first ConstSpec of that constant declaration, which has index 0. Hence the value of iota and thus a is 0.

@griesemer griesemer modified the milestones: Go1.10, Go1.11 Oct 20, 2017

@griesemer griesemer added the NeedsFix label May 31, 2018

@griesemer griesemer modified the milestones: Go1.11, Unplanned May 31, 2018

@griesemer griesemer assigned griesemer and unassigned mdempsky May 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.