]> Cypherpunks repositories - gostls13.git/commitdiff
spec: describe constraint parsing ambiguity and work-around more precisely
authorRobert Griesemer <gri@golang.org>
Thu, 16 Dec 2021 18:25:07 +0000 (10:25 -0800)
committerRobert Griesemer <gri@golang.org>
Fri, 17 Dec 2021 03:28:06 +0000 (03:28 +0000)
The new description matches the implementation (CL 370774).

Also, in the section on type constraints, use "defines" instead of
"determines" because the constraint interface defines the type set
which is precisely the set of acceptable type arguments.

For #49482.

Change-Id: I6f30f49100e8ba8bec0a0f1b450f88cae54312eb
Reviewed-on: https://go-review.googlesource.com/c/go/+/372874
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
doc/go_spec.html

index ed98f5375f19bb10eb637e3812ca0cc164b839f7..c0b224f9776fd9f3cbfeef7a6f52a790e3f9ad51 100644 (file)
@@ -2604,7 +2604,8 @@ has a corresponding (meta-)type which is called its
 <p>
 A parsing ambiguity arises when the type parameter list for a parameterized type
 declares a single type parameter with a type constraint of the form <code>*C</code>
-or <code>(C)</code>:
+or <code>(C)</code> where <code>C</code> is not a (possibly parenthesized)
+<a href="#Types">type literal</a>:
 </p>
 
 <pre>
@@ -2616,17 +2617,19 @@ type T[P (C)] …
 In these rare cases, the type parameter declaration is indistinguishable from
 the expressions <code>P*C</code> or <code>P(C)</code> and the type declaration
 is parsed as an array type declaration.
-To resolve the ambiguity, embed the constraint in an interface:
+To resolve the ambiguity, embed the constraint in an interface or use a trailing
+comma:
 </p>
 
 <pre>
 type T[P interface{*C}] …
+type T[P *C,] …
 </pre>
 
 <h4 id="Type_constraints">Type constraints</h4>
 
 <p>
-A type constraint is an <a href="#Interface_types">interface</a> that determines the
+A type constraint is an <a href="#Interface_types">interface</a> that defines the
 set of permissible type arguments for the respective type parameter and controls the
 operations supported by values of that type parameter.
 </p>