From 4b58b3077801b83c7ebc8eca23c7f63913d0778f Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Wed, 14 Sep 2022 11:47:08 +0700 Subject: [PATCH] spec: describe an edge case of slice-to-array conversions 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 Auto-Submit: Cuong Manh Le Reviewed-by: Robert Griesemer Reviewed-by: Cherry Mui Auto-Submit: Robert Griesemer Run-TryBot: Cuong Manh Le --- doc/go_spec.html | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index ff75190bb7..e2163b466d 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -5542,10 +5542,10 @@ a run-time panic occurs.
 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:])  // &s1[0] == &s[1]
@@ -5553,8 +5553,9 @@ s2 := (*[2]byte)(s)      // &s2[0] == &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
-- 
2.48.1