summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2022-09-14 11:47:08 +0700
committerGopher Robot <gobot@golang.org>2022-09-21 14:06:15 +0000
commit4b58b3077801b83c7ebc8eca23c7f63913d0778f (patch)
tree433f4517fe6caa07ad4ac63e5c43e2c403fb4fa3 /doc
parentc70fd4b30aba5db2df7b5f6b0833c62b909f50eb (diff)
downloadgo-git-4b58b3077801b83c7ebc8eca23c7f63913d0778f.tar.gz
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 <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>
Diffstat (limited to 'doc')
-rw-r--r--doc/go_spec.html15
1 files 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 @@
<!--{
"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