From: Robert Griesemer
+A link of the form [Go 1.xx] indicates that a described
+language feature (or some aspect of it) was changed or added with language version 1.xx and
+thus requires at minimum that language version to build.
+For details, see the linked section
+in the appendix.
+
@@ -263,7 +271,8 @@ continue for import return var
The following character sequences represent operators
-(including assignment operators) and punctuation:
+(including assignment operators) and punctuation
+[Go 1.18]:
Source code representation
+ & += &= && == != ( )
@@ -281,7 +290,8 @@ An integer literal is a sequence of digits representing an
integer constant.
An optional prefix sets a non-decimal base:
0b
or 0B
for binary, 0
, 0o
, or 0O
for octal,
-and 0x
or 0X
for hexadecimal.
+and 0x
or 0X
for hexadecimal
+[Go 1.13].
A single 0
is considered a decimal zero.
In hexadecimal literals, letters a
through f
and A
through F
represent values 10 through 15.
@@ -347,7 +357,8 @@ prefix, an integer part (hexadecimal digits), a radix point, a fractional part (
and an exponent part (p
or P
followed by an optional sign and decimal digits).
One of the integer part or the fractional part may be elided; the radix point may be elided as well,
but the exponent part is required. (This syntax matches the one given in IEEE 754-2008 §5.12.3.)
-An exponent value exp scales the mantissa (integer and fractional part) by 2exp.
+An exponent value exp scales the mantissa (integer and fractional part) by 2exp
+[Go 1.13].
@@ -411,7 +422,8 @@ It consists of an integer or
floating-point literal
followed by the lowercase letter i
.
The value of an imaginary literal is the value of the respective
-integer or floating-point literal multiplied by the imaginary unit i.
+integer or floating-point literal multiplied by the imaginary unit i
+[Go 1.13]
@@ -1340,6 +1352,7 @@ interface{}For convenience, the predeclared type
any
is an alias for the empty interface. +[Go 1.18]@@ -1375,13 +1388,15 @@ as the
File
interface. In a slightly more general form an interfaceT
may use a (possibly qualified) interface type nameE
as an interface element. This is called -embedding interfaceE
inT
. +embedding interfaceE
inT
+[Go 1.14]. The type set ofT
is the intersection of the type sets defined byT
's explicitly declared methods and the type sets ofT
âs embedded interfaces. In other words, the type set ofT
is the set of all types that implement all the explicitly declared methods ofT
and also all the methods of -E
. +E
+[Go 1.18].@@ -1420,7 +1435,8 @@ type ReadCloser interface {In their most general form, an interface element may also be an arbitrary type term
@@ -2303,7 +2319,9 @@ as an operand, and in aT
, or a term of the form~T
specifying the underlying typeT
, -or a union of termst1|t2|â¦|tn
. +or a union of termst1|t2|â¦|tn
+[Go 1.18]. Together with method specifications, these elements enable the precise definition of an interface's type set as follows:The following identifiers are implicitly declared in the -universe block: +universe block +[Go 1.18] +[Go 1.21]:
Types: @@ -2487,7 +2505,8 @@ TypeSpec = AliasDecl | TypeDef .Alias declarations
-An alias declaration binds an identifier to the given type. +An alias declaration binds an identifier to the given type +[Go 1.9].
@@ -2636,7 +2655,8 @@ func (l *List[T]) Len() int { ⦠} A type parameter list declares the type parameters of a generic function or type declaration. The type parameter list looks like an ordinary function parameter list except that the type parameter names must all be present and the list is enclosed -in square brackets rather than parentheses. +in square brackets rather than parentheses +[Go 1.18].@@ -2719,7 +2739,8 @@ type T6[P int] struct{ f *T6[P] } // ok: reference to T6 is not in type paraA type constraint is an interface that defines the set of permissible type arguments for the respective type parameter and controls the -operations supported by values of that type parameter. +operations supported by values of that type parameter +[Go 1.18].
@@ -2749,7 +2770,8 @@ other interfaces based on their type sets. But this should get us going for now. The predeclared interface typecomparable
denotes the set of all non-interface types that are -strictly comparable. +strictly comparable +[Go 1.18].@@ -2782,7 +2804,8 @@ if
@@ -4306,7 +4329,7 @@ with the same underlying array.T
is an element of the type set defined byC
; i.e., ifT
implementsC
. As an exception, a strictly comparable type constraint may also be satisfied by a comparable -(not necessarily strictly comparable) type argument. +(not necessarily strictly comparable) type argument +[Go 1.20]. More precisely:A generic function or type is instantiated by substituting type arguments -for the type parameters. +for the type parameters [Go 1.18]. Instantiation proceeds in two steps:
@@ -4759,6 +4782,7 @@ to the type of the other operand.The right operand in a shift expression must have integer type +[Go 1.13] or be an untyped constant representable by a value of type
uint
. If the left operand of a non-constant shift expression is an untyped constant, @@ -5426,7 +5450,8 @@ in any of these cases:x
is a string andT
is a slice of bytes or runes.- @@ -6553,7 +6578,7 @@ for { S() } is the same as for true { S() }x
is a slice,T
is an array or a pointer to an array, +x
is a slice,T
is an array [Go 1.20] + or a pointer to an array [Go 1.17], and the slice and array types have identical element types.A "for" statement with a "range" clause iterates through all entries of an array, slice, string or map, values received on -a channel, or integer values from zero to an upper limit. +a channel, or integer values from zero to an upper limit [Go 1.22]. For each entry it assigns iteration values to corresponding iteration variables if present and then executes the block.
@@ -7249,7 +7274,8 @@ n3 := copy(b, "Hello, World!") // n3 == 5, b is []byte("Hello")The built-in function
clear
takes an argument of map, slice, or type parameter type, -and deletes or zeroes out all elements. +and deletes or zeroes out all elements +[Go 1.21].@@ -7516,7 +7542,8 @@ The precise behavior is implementation-dependent. The built-in functionsmin
andmax
compute the smallest—or largest, respectively—value of a fixed number of arguments of ordered types. -There must be at least one argument. +There must be at least one argument +[Go 1.21].@@ -8296,7 +8323,8 @@ of constant size.
The function
Add
addslen
toptr
-and returns the updated pointerunsafe.Pointer(uintptr(ptr) + uintptr(len))
. +and returns the updated pointerunsafe.Pointer(uintptr(ptr) + uintptr(len))
+[Go 1.17]. Thelen
argument must be of integer type or an untyped constant. A constantlen
argument must be representable by a value of typeint
; if it is an untyped constant it is given typeint
. @@ -8316,7 +8344,8 @@ and whose length and capacity arelen
.except that, as a special case, if
ptr
isnil
andlen
is zero, -Slice
returnsnil
. +Slice
returnsnil
+[Go 1.17].@@ -8325,14 +8354,16 @@ A constant
len
argument must be non-negative and run-time panic occurs. +a run-time panic occurs +[Go 1.17].The function
SliceData
returns a pointer to the underlying array of theslice
argument. If the slice's capacitycap(slice)
is not zero, that pointer is&slice[:1][0]
. Ifslice
isnil
, the result isnil
. -Otherwise it is a non-nil
pointer to an unspecified memory address. +Otherwise it is a non-nil
pointer to an unspecified memory address +[Go 1.20].@@ -8341,12 +8372,14 @@ The function
String
returns astring
value whose under The same requirements apply to theptr
andlen
argument as in the functionSlice
. Iflen
is zero, the result is the empty string""
. Since Go strings are immutable, the bytes passed toString
must not be modified afterwards. +[Go 1.20]The function
StringData
returns a pointer to the underlying bytes of thestr
argument. For an empty string the return value is unspecified, and may benil
. -Since Go strings are immutable, the bytes returned byStringData
must not be modified. +Since Go strings are immutable, the bytes returned byStringData
must not be modified +[Go 1.20].Size and alignment guarantees
@@ -8387,6 +8420,141 @@ A struct or array type has size zero if it contains no fields (or elements, respAppendix
+Language versions
+ ++The Go 1 compatibility guarantee ensures that +programs written to the Go 1 specification will continue to compile and run +correctly, unchanged, over the lifetime of that specification. +More generally, as adjustements are made and features added to the language, +the compatibility guarantee ensures that a Go program that works with a +specific Go language version will continue to work with any subsequent version. +
+ ++For instance, the ability to use the prefix
+ +0b
for binary +integer literals was introduced with Go 1.13, indicated +by [Go 1.13] in the section on +integer literals. +Source code containing an integer literal such as0b1011
+will be rejected if the implied or required language version used by +the compiler is older than Go 1.13. ++The following table describes the minimum language version required for +features introduced after Go 1. +
+ +Go 1.9
++
+ +- +An alias declaration may be used to declare an alias name for a type. +
+Go 1.13
++
+ +- +Integer literals may use the prefixes
+0b
,0B
,0o
, +and0O
for binary, and octal literals, respectively. +- +Hexadecimal floating-point literals may be written using the prefixes +
+0x
and0X
. +- +The imaginary suffix
+i
may be used with any (binary, decimal, hexadecimal) +integer or floating-point literal, not just decimal literals. +- +The digits of any number literal may be separated (grouped) +using underscores
+_
. +- +The shift count in a shift operation may be a signed integer type. +
+Go 1.14
++
+ +- +Emdedding a method more than once through different embedded interfaces +is not an error. +
+Go 1.17
++
+ +- +A slice may be converted to an array pointer if the slice and array element +types match, and the array is not longer than the slice. +
+- +The built-in package
+unsafe
includes the new functions +Add
andSlice
. +Go 1.18
++The 1.18 release adds polymorphic functions and types ("generics") to the language. +Specifically: +
++
+ +- +The set of operators and punctuation includes the new token
+~
. +- +Function and type declarations may declare type parameters. +
+- +Interface types may embed arbitrary types (not just type names of interfaces) +as well as union and
+~T
type elements. +- +The set of predeclared types includes the new types +
+any
andcomparable
. +Go 1.20
++
+ +- +A slice may be converted to an array if the slice and array element +types match and the array is not longer than the slice. +
+- +The built-in package
+unsafe
includes the new functions +SliceData
,String
, andStringData
. +- +Comparable types (such as ordinary interfaces) may satisfy +
+comparable
constraints, even if the type arguments are not strictly comparable. +Go 1.21
++
+ +- +The set of predeclared functions includes the new functions +
+min
,max
, andclear
. +- +Type inference uses the types of interface methods for inference. +It also infers type arguments for generic functions assigned to variables or +passed as arguments to other (possibly generic) functions. +
+Go 1.22
++
+- +A "for" statement with a "range" clause may iterate over +integer values from zero to an upper limit. +
+Type unification rules