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

Closed
griesemer opened this issue Oct 19, 2017 · 5 comments
Closed

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

griesemer opened this issue Oct 19, 2017 · 5 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@griesemer
Copy link
Contributor

https://play.golang.org/p/K0Vga-Y1fv reports an error, but the spec doesn't prohibit this code.
https://play.golang.org/p/MbPQO9FJku 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.

@griesemer
Copy link
Contributor Author

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

@go101
Copy link

go101 commented Oct 20, 2017

There is a paradox

package main

import "unsafe"

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

func main() {
}

The current gc thinks a is 0.

@mdempsky
Copy link
Member

const a = iota sets a to 0.

@griesemer
Copy link
Contributor Author

@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 The path to resolution is known, but the work has not been done. 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
@gopherbot
Copy link

Change https://golang.org/cl/194717 mentions this issue: cmd/compile: allow iota inside function in a ConstSpec

@golang golang locked and limited conversation to collaborators Sep 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants