1
0
mirror of https://github.com/golang/go synced 2024-09-24 09:20:15 -06:00

Allow indexing of slice types, but not pointer to slice type.

Allow indexing of string type, but not pointer to string type.
Do not allow indexing of pointer to map type.

R=r
DELTA=18  (14 added, 0 deleted, 4 changed)
OCL=30586
CL=30754
This commit is contained in:
Russ Cox 2009-06-25 14:43:55 -07:00
parent 4866223c2e
commit eaa92e027b

View File

@ -2155,17 +2155,31 @@ The value <code>x</code> is called the
<i>array index</i> or <i>map key</i>, respectively. The following <i>array index</i> or <i>map key</i>, respectively. The following
rules apply: rules apply:
</p> </p>
<p> <p>
For <code>a</code> of type <code>A</code> or <code>*A</code> For <code>a</code> of type <code>A</code> or <code>*A</code>
where <code>A</code> is an array type (§Array types): where <code>A</code> is an array type (§Array types),
or for <code>a</code> of type <code>S</code> where <code>S</code> is a slice type (§Slice types):
</p> </p>
<ul> <ul>
<li><code>x</code> must be an integer value and <code>0 &lt;= x &lt; len(a)</code> <li><code>x</code> must be an integer value and <code>0 &lt;= x &lt; len(a)</code>
<li><code>a[x]</code> is the array element at index <code>x</code> and the type of <li><code>a[x]</code> is the array element at index <code>x</code> and the type of
<code>a[x]</code> is the element type of <code>A</code> <code>a[x]</code> is the element type of <code>A</code>
</ul> </ul>
<p> <p>
For <code>a</code> of type <code>M</code> or <code>*M</code> For <code>a</code> of type <code>T</code>
where <code>T</code> is a string type (§Strings):
</p>
<ul>
<li><code>x</code> must be an integer value and <code>0 &lt;= x &lt; len(a)</code>
<li><code>a[x]</code> is the byte at index <code>x</code> and the type of
<code>a[x]</code> is <code>byte</code>
<li><code>a[x]</code> may not be assigned to
</ul>
<p>
For <code>a</code> of type <code>M</code>
where <code>M</code> is a map type (§Map types): where <code>M</code> is a map type (§Map types):
</p> </p>
<ul> <ul>
@ -2248,7 +2262,7 @@ For arrays or strings, the indexes
for slices, the upper bound is the capacity rather than the length. for slices, the upper bound is the capacity rather than the length.
<p> <p>
If the sliced operand is a string, the result of the slice operation is another, new If the sliced operand is a string, the result of the slice operation is another, new
string (§String types). If the sliced operand is an array or slice, the result string (§Strings). If the sliced operand is an array or slice, the result
of the slice operation is a slice (§Slice types). of the slice operation is a slice (§Slice types).
</p> </p>