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
Assignees
Labels
Milestone

Comments

@griesemer
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link

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

Copy link
Member

@mdempsky mdempsky commented Oct 20, 2017

const a = iota sets a to 0.

@griesemer

This comment has been minimized.

Copy link
Contributor Author

@griesemer 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
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Sep 11, 2019

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

@gopherbot gopherbot closed this in 55c0ad4 Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.