mirror of https://github.com/golang/go.git
spec: clarify that each block has its own version of iota
Issue #15550 is clearly an esoteric case but the spec was silent about it and we had diverging implementations. By making `iota` and index that is relative to the respective constant declaration, nested const declarations won't affect outer values of `iota`. cmd/compile and go/types already follow this semantics. Fixes #15550. Change-Id: If138189e3ea4373f8ba50ac6fb1d219b481f8698 Reviewed-on: https://go-review.googlesource.com/71750 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
58d7231b2f
commit
52dd39965e
|
|
@ -1,6 +1,6 @@
|
|||
<!--{
|
||||
"Title": "The Go Programming Language Specification",
|
||||
"Subtitle": "Version of October 17, 2017",
|
||||
"Subtitle": "Version of October 18, 2017",
|
||||
"Path": "/ref/spec"
|
||||
}-->
|
||||
|
||||
|
|
@ -1866,8 +1866,8 @@ const (
|
|||
<p>
|
||||
Within a <a href="#Constant_declarations">constant declaration</a>, the predeclared identifier
|
||||
<code>iota</code> represents successive untyped integer <a href="#Constants">
|
||||
constants</a>. It is reset to 0 whenever the reserved word <code>const</code>
|
||||
appears in the source and increments after each <a href="#ConstSpec">ConstSpec</a>.
|
||||
constants</a>. Its value is the index of the respective <a href="#ConstSpec">ConstSpec</a>
|
||||
in that constant declaration, starting at zero.
|
||||
It can be used to construct a set of related constants:
|
||||
</p>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue