From 6fb07317e5e7997a1e44ccb6984229c77dc186a3 Mon Sep 17 00:00:00 2001
From: Robert Griesemer
The language predeclares certain type names.
Others are introduced with type declarations
-or type parameter lists.
+or type parameter lists.
Composite types—array, struct, pointer, function,
interface, slice, map, and channel types—may be constructed using
type literals.
@@ -1459,7 +1459,7 @@
-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
By definition, a core type is never a defined type,
-type parameter, or
+type parameter, or
interface type.
A constant
-If the type definition specifies type parameters,
+If the type definition specifies type parameters,
the type name denotes a generic type.
Generic types must be instantiated when they
are used.
@@ -2538,7 +2539,7 @@
A type parameter list declares the type parameters of a generic function or type declaration.
@@ -2577,22 +2578,22 @@
A parsing ambiguity arises when the type parameter list for a generic type
-declares a single type parameter with a type constraint of the form
-In these rare cases, the type parameter declaration is indistinguishable from
-the expressions Types
General interfaces
P
:
Core types
Representability
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:
Declarations and scope
A declaration binds a non-blank identifier to a
constant,
type,
+type parameter,
variable,
function,
label, or
@@ -2502,7 +2503,7 @@ Type definitions
Type definitions
func (l *List[T]) Len() int { … }
-Type parameter lists
+Type parameter declarations
Type parameter lists
*C
-or (C)
where C
is not a (possibly parenthesized)
-type literal:
+declares a single type parameter P
with a constraint C
+such that the text P C
forms a valid expression:
type T[P *C] …
type T[P (C)] …
+type T[P *C|Q] …
+…
P*C
or P(C)
and the type declaration
-is parsed as an array type declaration.
-To resolve the ambiguity, embed the constraint in an interface or use a trailing
-comma:
+In these rare cases, the type parameter list is indistinguishable from an
+expression and the type declaration is parsed as an array type declaration.
+To resolve the ambiguity, embed the constraint in an
+interface or use a trailing comma:
@@ -2606,6 +2607,11 @@
Type parameter lists
with a generic type.
@@ -2625,10 +2631,10 @@
-[T *P] // = [T interface{*P}] -[T ~int] // = [T interface{~int}] -[T int|string] // = [T interface{int|string}] -type Constraint ~int // illegal: ~int is not inside a type parameter list +[T []P] // = [T interface{[]P}] +[T ~int] // = [T interface{~int}] +[T int|string] // = [T interface{int|string}] +type Constraint ~int // illegal: ~int is not inside a type parameter list