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

Open
griesemer opened this Issue Oct 19, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@griesemer
Contributor

griesemer commented Oct 19, 2017

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

This comment has been minimized.

Contributor

griesemer 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.

@go101

This comment has been minimized.

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

This comment has been minimized.

Member

mdempsky commented Oct 20, 2017

const a = iota sets a to 0.

@griesemer

This comment has been minimized.

Contributor

griesemer 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