]> Cypherpunks.ru repositories - gostls13.git/commitdiff
spec: describe an edge case of slice-to-array conversions
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 14 Sep 2022 04:47:08 +0000 (11:47 +0700)
committerGopher Robot <gobot@golang.org>
Wed, 21 Sep 2022 14:06:15 +0000 (14:06 +0000)
Converting from nil slice to zero element array is ok, so explicitly
describe the behavior in the spec.

For #46505

Change-Id: I68f432deb6c21a7549bf7e870185fc62504b37f7
Reviewed-on: https://go-review.googlesource.com/c/go/+/430835
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>

doc/go_spec.html

index ff75190bb7994ab53f2f2152546bb4383ccc9cd5..e2163b466d82955748a9f0e6a46d75cd16cb0e3f 100644 (file)
@@ -1,6 +1,6 @@
 <!--{
        "Title": "The Go Programming Language Specification",
-       "Subtitle": "Version of September 8, 2022",
+       "Subtitle": "Version of September 21, 2022",
        "Path": "/ref/spec"
 }-->
 
@@ -5542,10 +5542,10 @@ a <a href="#Run_time_panics">run-time panic</a> occurs.
 <pre>
 s := make([]byte, 2, 4)
 
-a0 := ([0]byte)(s)
-a1 := ([1]byte)(s[1:])   // a1[0] == s[1]
-a2 := ([2]byte)(s)       // a2[0] == s[0]
-a4 := ([4]byte)(s)       // panics: len([4]byte) > len(s)
+a0 := [0]byte(s)
+a1 := [1]byte(s[1:])     // a1[0] == s[1]
+a2 := [2]byte(s)         // a2[0] == s[0]
+a4 := [4]byte(s)         // panics: len([4]byte) > len(s)
 
 s0 := (*[0]byte)(s)      // s0 != nil
 s1 := (*[1]byte)(s[1:])  // &amp;s1[0] == &amp;s[1]
@@ -5553,8 +5553,9 @@ s2 := (*[2]byte)(s)      // &amp;s2[0] == &amp;s[0]
 s4 := (*[4]byte)(s)      // panics: len([4]byte) > len(s)
 
 var t []string
-t0 := (*[0]string)(t)    // t0 == nil
-t1 := (*[1]string)(t)    // panics: len([1]string) > len(t)
+t0 := [0]string(t)       // ok for nil slice t
+t1 := (*[0]string)(t)    // t1 == nil
+t2 := (*[1]string)(t)    // panics: len([1]string) > len(t)
 
 u := make([]byte, 0)
 u0 := (*[0]byte)(u)      // u0 != nil