]> Cypherpunks repositories - gostls13.git/commitdiff
spec: clarify acceptable indices in array/slice composite literals
authorRobert Griesemer <gri@golang.org>
Wed, 5 Oct 2016 22:59:09 +0000 (15:59 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 6 Oct 2016 20:37:39 +0000 (20:37 +0000)
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>
doc/go_spec.html

index 6e07c945e173bce91a01a94e1679588624377bbd..5f0a16c0ff0993136d26b511c9b1f18dea6a8d74 100644 (file)
@@ -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.