-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: definition for iota doesn't make sense for nested ConstDecls #15550
Comments
Two side thoughts:
|
Yes, I would agree that there's (among other things) a spec issue here - each scope should have its own iota. I think we can safely make that adjustment in the spec w/o affecting real-life code. Regarding the comments:
|
@griesemer Ah, agreed that strict interpretation supports printing 4, not 3. (And so gccgo is actually technically conforming.) |
Per discussion on #15551, I'm reclassifying this as an issue against the spec. Based on how we resolve this issue, we can then (re)open issues against the compilers / typecheckers to fix their behavior as appropriate. |
CL https://golang.org/cl/36122 mentions this issue. |
When switching to the new parser, I changed cmd/compile to handle iota per an intuitive interpretation of how nested constant declarations should work (which also matches go/types). Note: if we end up deciding that the current spec wording is intentional (i.e., confirming gccgo's current behavior), the test will need to be updated to expect 4 instead of 1. Updates #15550. Change-Id: I441f5f13209f172b73ef75031f2a9daa5e985277 Reviewed-on: https://go-review.googlesource.com/36122 Reviewed-by: David Crawshaw <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Reviewed-by: Josh Bleecher Snyder <[email protected]> Run-TryBot: Josh Bleecher Snyder <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
Change https://golang.org/cl/71750 mentions this issue: |
Oops, I just noticed there are still two mentions of
Since we got rid of the definition that I think there's also still the question of whether this is valid:
Currently, I think the spec's wording permits it, but none of the compilers do. I'm leaning towards the compilers are wrong here. Partly because I think disallowing this in the spec is too clumsy, and partly because it seems natural that function literals should be allowed to still access any declared objects in scope just as if they weren't in a function literal. |
@mdempsky All good points. I'm fixing the "increments" parts ( I think we just don't need those comments anymore, including the references to "reset" ). Still thinking about the use of iota inside a function with const decl. |
@mdempsky We should probably allow iotas anywhere in an expression. There's no real harm here, and as you say, it would be pretty awkward to exclude selected special cases. For instance, this actually works:
|
Change https://golang.org/cl/71912 mentions this issue: |
https://golang.org/cl/71750 specifies iota values as indices, thus making them independent from nested constant declarations. This CL removes some of the comments in the examples that were still referring to the old notion of iotas being incremented and reset. As an aside, please note that the spec still permits the use of iota in a nested function (like before). Specifically, the following cases are permitted by the spec (as before): 1) const _ = len([iota]int{}) 2) const _ = unsafe.Sizeof(func(){ _ = iota }) For #15550. Change-Id: I9e5fec75daf7b628b1e08d970512397e9c348923 Reviewed-on: https://go-review.googlesource.com/71912 Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Rob Pike <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
This program should print 1, but cmd/compile rejects it with an "undefined: iota" error.
The text was updated successfully, but these errors were encountered: