From 6fb07317e5e7997a1e44ccb6984229c77dc186a3 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 8 Mar 2022 13:11:04 -0800 Subject: [PATCH] spec: more adjustments/corrections - Change section title from "Type parameters lists" to "Type parameter declarations" as the enclosing section is about declarations. - Correct section on parsing ambiguity in type parameter lists. - Rephrase paragraphs on type parameters for method receivers and adjust examples. - Remove duplicate prose in section on function argument type inference. - Clarified "after substitution" column in Instantiations section. Change-Id: Id76be9804ad96a3f1221e5c4942552dde015dfcb Reviewed-on: https://go-review.googlesource.com/c/go/+/390994 Trust: Robert Griesemer Reviewed-by: Ian Lance Taylor --- doc/go_spec.html | 92 +++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 000b0c5e670a3..cfbb17e3bba8e 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -807,7 +807,7 @@

Types

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 @@

General interfaces

-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:

@@ -1769,7 +1769,7 @@

Core types

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

@@ -1965,7 +1965,7 @@

Representability

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:

@@ -2105,6 +2105,7 @@

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

-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 @@

Type definitions

func (l *List[T]) Len() int { … } -

Type parameter lists

+

Type parameter declarations

A type parameter list declares the type parameters of a generic function or type declaration. @@ -2577,22 +2578,22 @@

Type parameter lists

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 *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] …
+…
 

-In these rare cases, the type parameter declaration is indistinguishable from -the expressions 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.

+ +

Type constraints

@@ -2625,10 +2631,10 @@

Type constraints

-[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