From: Robert Griesemer cap(a)
.
-A new, initialized slice value for a given element type T
is
+A new, initialized slice value for a given element type T
may be
made using the built-in function
make
,
which takes a slice type
@@ -1422,7 +1422,7 @@ interface {
~int
}
-// An interface representing all types with underlying type int which implement the String method.
+// An interface representing all types with underlying type int that implement the String method.
interface {
~int
String() string
@@ -1455,32 +1455,32 @@ Union elements denote unions of type sets:
-// The Floats interface represents all floating-point types +// The Float interface represents all floating-point types // (including any named types whose underlying types are // either float32 or float64). -type Floats interface { +type Float interface { ~float32 | ~float64 }
-In a union, a term cannot be a type parameter, and the type sets of all
+In a union, a term cannot be a type parameter, and the type sets of all
non-interface terms must be pairwise disjoint (the pairwise intersection of the type sets must be empty).
Given a type parameter P
:
interface { - P // illegal: the term P is a type parameter - int | P // illegal: the term P is a type parameter - ~int | MyInt // illegal: the type sets for ~int and MyInt are not disjoint (~int includes MyInt) - float32 | Floats // overlapping type sets but Floats is an interface + P // illegal: P is a type parameter + int | P // illegal: P is a type parameter + ~int | MyInt // illegal: the type sets for ~int and MyInt are not disjoint (~int includes MyInt) + float32 | Float // overlapping type sets but Float is an interface }
Implementation restriction:
-A union with more than one term cannot contain the
+A union (with more than one term) cannot contain the
predeclared identifier comparable
or interfaces that specify methods, or embed comparable
or interfaces
that specify methods.
@@ -1494,12 +1494,12 @@ non-interface types.
-var x Floats // illegal: Floats is not a basic interface +var x Float // illegal: Float is not a basic interface -var x interface{} = Floats(nil) // illegal +var x interface{} = Float(nil) // illegal type Floatish struct { - f Floats // illegal + f Float // illegal }@@ -1545,7 +1545,7 @@ A type
T
implements an interface I
if
-A value x
of type T
implements an interface if T
+A value of type T
implements an interface if T
implements the interface.
T
has an underlying type: If T
is one of the predeclared boolean, numeric, or string types, or a type literal,
the corresponding underlying type is T
itself.
Otherwise, T
's underlying type is the underlying type of the
-type to which T
refers in its type
-declaration. The underlying type of a type parameter is the
-underlying type of its type constraint, which
-is always an interface.
+type to which T
refers in its declaration.
+For a type parameter that is the underlying type of its
+type constraint, which is always an interface.
@@ -1755,7 +1754,7 @@ direction.-All other interfaces don't have a core type. +No other interfaces have a core type.
@@ -1795,7 +1794,7 @@ interface{ ~[]*data; String() string } // []*data
-Examples of interfaces whithout core types: +Examples of interfaces without core types:
@@ -1973,21 +1972,21 @@ defined type while the latter is a type literalAssignability
-A value
x
is assignable to a variable of typeT
+A valuex
of typeV
is assignable to a variable of typeT
("x
is assignable toT
") if one of the following conditions applies:
x
's type is identical to T
.
+V
and T
are identical.
x
's type V
and T
have identical
+V
and T
have identical
underlying types and at least one of V
or T
is not a named type.
x
's type V
and T
are channel types with
+V
and T
are channel types with
identical element types, V
is a bidirectional channel,
and at least one of V
or T
is not a named type.
-The given type cannot be a type parameter in a type definition. +In a type definition the given type cannot be a type parameter.
@@ -2604,8 +2598,8 @@ func f[T any]() {
-A generic type may also have methods associated with it. In this case, -the method receivers must declare the same number of type parameters as +A generic type may also have methods associated with it. +In this case, the method receivers must declare the same number of type parameters as present in the generic type definition.
@@ -2899,12 +2893,12 @@ func IndexRune(s string, r rune) int {If the function declaration specifies type parameters, the function name denotes a generic function. -Generic functions must be instantiated when they -are used. +A generic function must be instantiated before it can be +called or used as a value.
-func min[T constraints.Ordered](x, y T) T { +func min[T ~int|~float64](x, y T) T { if x < y { return x } @@ -2963,7 +2957,7 @@ the non-blank method and field names must be distinct.-Given defined type
Point
, the declarations +Given defined typePoint
the declarations@@ -3758,7 +3752,7 @@ The following rules apply:-If
a
is not a map: +Ifa
is neither a map nor a type parameter:
x
must be an untyped constant or its
@@ -4298,7 +4292,7 @@ inferrable from the ordinary (non-type) function arguments.
-func min[T constraints.Ordered](x, y T) T { ⦠} +func min[T ~int|~float64](x, y T) T { ⦠} f := min // illegal: min must be instantiated when used without being called minInt := min[int] // minInt has type func(x, y int) int @@ -4550,7 +4544,7 @@ Example:-func min[T constraints.Ordered](x, y T) T +func min[T ~int|~float64](x, y T) T var x int min(x, 2.0) // T is int, inferred from typed argument x; 2.0 is assignable to int