From 18e1a5a0859a268af83d3bbe855b8bf3b2d25298 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 10 Feb 2022 21:51:04 -0800 Subject: [PATCH] spec: combine section on type parameters and type parameter lists This change moves the relevant prose of the section on type parameters into the section on type parameter lists and eliminates the former. With this change, the section on types now exclusively describes all Go composite types. User-defined named types (defined types and type parameters) are described with their declarations. Change-Id: I3e421cd236e8801d31a4a81ff1e5ec9933e3ed20 Reviewed-on: https://go-review.googlesource.com/c/go/+/385037 Trust: Robert Griesemer Reviewed-by: Ian Lance Taylor --- doc/go_spec.html | 58 +++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 35 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index d3dc7ce9a3..b63aba5b16 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,5 +1,5 @@ @@ -1688,25 +1688,6 @@ and a second goroutine receives them, the values are received in the order sent.

-

Type parameters

- -

-A type parameter is an (unqualified) type name declared in the -type parameter list of a -function declaration or -type definition; or in the receiver specification -of a method declaration that is associated -with a generic type. -A type parameter acts as a place holder for an (as of yet) unknown type in the declaration; -the type parameter is replaced with a type argument upon -instantiation of the generic function or type. -

- -

-The properties of a type parameter are determined by its -type constraint. -

-

Properties of types and values

Underlying types

@@ -1790,7 +1771,7 @@ depending on the direction of the directional channels present.

By definition, a core type is never a defined type, -type parameter, or +type parameter, or interface type.

@@ -2047,7 +2028,7 @@ to T.

A constant x is representable by a value of type T, -where T is not a type parameter, +where T is not a type parameter, if one of the following conditions applies:

@@ -2628,8 +2609,7 @@ func (l *List[T]) Len() int { … }

Type parameter lists

-A type parameter list declares the type parameters -in a generic function or type declaration. +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. @@ -2642,9 +2622,11 @@ TypeParamDecl = IdentifierList TypeConstraint .

-Each identifier declares a type parameter. All non-blank names in the list must be unique. -Each type parameter is a new and different named type. +Each name declares a type parameter, which is a new and different named type +that acts as a place holder for an (as of yet) unknown type in the declaration. +The type parameter is replaced with a type argument upon +instantiation of the generic function or type.

@@ -2686,6 +2668,12 @@ type T[P interface{*C}] …
 type T[P *C,] …
 
+

+Type parameters may also be declared by the receiver specification +of a method declaration associated +with a generic type. +

+

Type constraints

@@ -3829,7 +3817,7 @@ For a of map type M:

-For a of type parameter type P: +For a of type parameter type P:

  • P must have specific types.
  • @@ -4023,7 +4011,7 @@ If the indices are out of range at run time, a run-ti

    For an expression x of interface type, -but not a type parameter, and a type T, +but not a type parameter, and a type T, the primary expression

    @@ -4840,7 +4828,7 @@ The bitwise logical and shift operators apply to integers only.

    -Excluding shifts, if the operand type is a type parameter, +Excluding shifts, if the operand type is a type parameter, it must have specific types, and the operator must apply to each specific type. The operands are represented as values of the type argument that the type parameter @@ -5295,7 +5283,7 @@ as for non-constant x.

    -Converting a constant to a type that is not a type parameter +Converting a constant to a type that is not a type parameter yields a typed constant.

    @@ -5350,7 +5338,7 @@ in any of these cases:
  • ignoring struct tags (see below), x's type and T are not - type parameters but have + type parameters but have identical underlying types.
  • @@ -6269,7 +6257,7 @@ switch x.(type) { Cases then match actual types T against the dynamic type of the expression x. As with type assertions, x must be of interface type, but not a -type parameter, and each non-interface type +type parameter, and each non-interface type T listed in a case must implement the type of x. The types listed in the cases of a type switch must all be different. @@ -6351,7 +6339,7 @@ if v == nil {

    -A type parameter or a generic type +A type parameter or a generic type may be used as a type in a case. If upon instantiation that type turns out to duplicate another entry in the switch, the first matching case is chosen.

    @@ -7092,7 +7080,7 @@ cap(s) [n]T, *[n]T array length (== n)

    -If the argument type is a type parameter P, +If the argument type is a type parameter P, P must have specific types, and the call len(e) (or cap(e) respectively) must be valid for each specific type of P. @@ -7316,7 +7304,7 @@ delete(m, k) // remove element m[k] from map m

    -If the type of m is a type parameter, +If the type of m is a type parameter, it must have specific types, all specific types must be maps, and they must all have identical key types.

    -- 2.50.0