mirror of
https://github.com/golang/go
synced 2024-11-26 18:06:55 -07:00
spec: clarify acceptable indices in array/slice composite literals
This simply documents the status quo accepted by cmd/compile, gccgo, and go/types. The new language matches the language used for indices of index expressions for arrays and slices. Fixes #16679. Change-Id: I65447889fbda9d222f2a9e6c10334d1b38c555f0 Reviewed-on: https://go-review.googlesource.com/30474 Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
parent
95a6572b2b
commit
a016ecfdcb
@ -1,6 +1,6 @@
|
||||
<!--{
|
||||
"Title": "The Go Programming Language Specification",
|
||||
"Subtitle": "Version of October 4, 2016",
|
||||
"Subtitle": "Version of October 6, 2016",
|
||||
"Path": "/ref/spec"
|
||||
}-->
|
||||
|
||||
@ -2286,8 +2286,10 @@ For array and slice literals the following rules apply:
|
||||
<li>Each element has an associated integer index marking
|
||||
its position in the array.
|
||||
</li>
|
||||
<li>An element with a key uses the key as its index; the
|
||||
key must be a constant integer expression.
|
||||
<li>An element with a key uses the key as its index. The
|
||||
key must be a non-negative constant representable by
|
||||
a value of type <code>int</code>; and if it is typed
|
||||
it must be of integer type.
|
||||
</li>
|
||||
<li>An element without a key uses the previous element's index plus one.
|
||||
If the first element has no key, its index is zero.
|
||||
|
Loading…
Reference in New Issue
Block a user