From: Robert Griesemer
-The length is part of the array's type and must be a
-constant expression that evaluates to a non-negative
-integer value. The length of array a can be discovered
+The length is part of the array's type; it must evaluate to a non-
+negative constant representable by a value
+of type int.
+The length of array a can be discovered
using the built-in function len.
The elements can be addressed by integer indices
-indices 0 through len(a)-1.
+0 through len(a)-1.
Array types are always one-dimensional but may be composed to form
multi-dimensional types.
x is called the
rules apply:
+If a is not a map:
+
x must be an integer value; it is in range if 0 <= x < len(a),
+ otherwise it is out of rangeint
+
For a of type A or *A
where A is an array type:
x must be an integer value; it is in range if 0 <= x < len(a),
- otherwise it is out of rangea is nil or if x is out of range at run time,
a run-time panic occursA is an array type:
For a of type S where S is a slice type:
x must be an integer value; it is in range if 0 <= x < len(a),
- otherwise it is out of rangenil or if x is out of range at run time,
a run-time panic occursa[x] is the slice element at index x and the type of
@@ -2529,9 +2535,7 @@ For a of type T
where T is a string type:
x must be an integer value; it is in range if 0 <= x < len(a),
- otherwise it is out of rangea is also constantx is out of range at run time,
a run-time panic occurslow and high are
in range if 0 <= low <= high <= len(a),
otherwise they are out of range.
For slices, the upper index bound is the slice capacity cap(a) rather than the length.
-A constant index must not be negative, and if both indices
+A constant index must be non-negative and representable by a value of type
+int.
+If both indices
are constant, they must satisfy low <= high. If a is nil
or if the indices are out of range at run time, a run-time panic occurs.
@@ -4985,8 +4991,9 @@ make(T, n) channel asynchronous channel of type T, buffer size n
The size arguments n and m must be integer values.
-A constant size argument must not be negative, and
-if both n and m are provided and are constant, then
+A constant size argument must be non-negative and
+representable by a value of type int.
+If both n and m are provided and are constant, then
n must be no larger than m.
If n is negative or larger than m at run time,
a run-time panic occurs.
@@ -4995,6 +5002,7 @@ a run-time panic occurs.
s := make([]int, 10, 100) // slice with len(s) == 10, cap(s) == 100 s := make([]int, 1e3) // slice with len(s) == cap(s) == 1000 +s := make([]int, 1<<63) // illegal: len(s) is not representable by a value of type int s := make([]int, 10, 0) // illegal: len(s) > cap(s) c := make(chan int, 10) // channel with a buffer size of 10 m := make(map[string]int, 100) // map with initial space for 100 elements