Commit a016ecfd authored by Robert Griesemer's avatar Robert Griesemer

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/30474Reviewed-by: default avatarRob Pike <r@golang.org>
parent 95a6572b
<!--{ <!--{
"Title": "The Go Programming Language Specification", "Title": "The Go Programming Language Specification",
"Subtitle": "Version of October 4, 2016", "Subtitle": "Version of October 6, 2016",
"Path": "/ref/spec" "Path": "/ref/spec"
}--> }-->
...@@ -2286,8 +2286,10 @@ For array and slice literals the following rules apply: ...@@ -2286,8 +2286,10 @@ For array and slice literals the following rules apply:
<li>Each element has an associated integer index marking <li>Each element has an associated integer index marking
its position in the array. its position in the array.
</li> </li>
<li>An element with a key uses the key as its index; the <li>An element with a key uses the key as its index. The
key must be a constant integer expression. 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>
<li>An element without a key uses the previous element's index plus one. <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. If the first element has no key, its index is zero.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment