diff --git a/doc/go_spec.html b/doc/go_spec.html index ab172ac40e..3e47ee7bad 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -1811,6 +1811,31 @@ interface{ chan int | chan<- string } // channels have different element interface{ <-chan int | chan<- int } // directional channels have different directions +

+Some operations (slice expressions, +append and copy) +rely on a slightly more loose form of core types which accept byte slices and strings. +Specifically, if there are exactly two types, []byte and string, +which are the underlying types of all types in the type set of interface T, +the core type of T is called bytestring. +

+ +

+Examples of interfaces with bytestring core types: +

+ +
+interface{ int }                          // int (same as ordinary core type)
+interface{ []byte | string }              // bytestring
+interface{ ~[]byte | myString }           // bytestring
+
+ +

+Note that bytestring is not a real type; it cannot be used to declare +variables are compose other types. It exists solely to describe the behavior of some +operations that read from a sequence of bytes, which may be a byte slice or a string. +

+

Type identity

@@ -3837,7 +3862,8 @@ a[low : high]

constructs a substring or slice. The core type of -a must be a string, array, pointer to array, or slice. +a must be a string, array, pointer to array, slice, or a +bytestring. The indices low and high select which elements of operand a appear in the result. The result has indices starting at 0 and length equal to @@ -5469,7 +5495,7 @@ string(runes{0x767d, 0x9d6c, 0x7fd4}) // "\u767d\u9d6c\u7fd4" == "白鵬翔" type myRune rune string([]myRune{0x266b, 0x266c}) // "\u266b\u266c" == "♫♬" -myString([]myRune{0x1F30E}) // "\U0001f30e" == "🌎" +myString([]myRune{0x1f30e}) // "\U0001f30e" == "🌎" @@ -7197,8 +7223,9 @@ The values x are passed to a parameter of type ...E and the respective parameter passing rules apply. As a special case, if the core type of s is []byte, -append also accepts a second argument with core type string -followed by .... This form appends the bytes of the string. +append also accepts a second argument with core type +bytestring followed by .... +This form appends the bytes of the byte slice or string.

@@ -7235,8 +7262,9 @@ with identical element type.
 The number of elements copied is the minimum of
 len(src) and len(dst).
 As a special case, if the destination's core type is []byte,
-copy also accepts a source argument with core type string.
-This form copies the bytes from the string into the byte slice.
+copy also accepts a source argument with core type
+ bytestring.
+This form copies the bytes from the byte slice or string into the byte slice.
 

@@ -7550,7 +7578,7 @@ and the Unicode replacement character U+FFFD.
 

-Assume we have compiled a package containing the package clause +Consider a compiled a package containing the package clause package math, which exports function Sin, and installed the compiled package in the file identified by "lib/math".