Skip to content

Commit 3c49583

Browse files
committed
spec: describe constraint parsing ambiguity and work-around more precisely
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 <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 2bdf34f commit 3c49583

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

doc/go_spec.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2604,7 +2604,8 @@ <h3 id="Type_parameter_lists">Type parameter lists</h3>
26042604
<p>
26052605
A parsing ambiguity arises when the type parameter list for a parameterized type
26062606
declares a single type parameter with a type constraint of the form <code>*C</code>
2607-
or <code>(C)</code>:
2607+
or <code>(C)</code> where <code>C</code> is not a (possibly parenthesized)
2608+
<a href="#Types">type literal</a>:
26082609
</p>
26092610

26102611
<pre>
@@ -2616,17 +2617,19 @@ <h3 id="Type_parameter_lists">Type parameter lists</h3>
26162617
In these rare cases, the type parameter declaration is indistinguishable from
26172618
the expressions <code>P*C</code> or <code>P(C)</code> and the type declaration
26182619
is parsed as an array type declaration.
2619-
To resolve the ambiguity, embed the constraint in an interface:
2620+
To resolve the ambiguity, embed the constraint in an interface or use a trailing
2621+
comma:
26202622
</p>
26212623

26222624
<pre>
26232625
type T[P interface{*C}] …
2626+
type T[P *C,] …
26242627
</pre>
26252628

26262629
<h4 id="Type_constraints">Type constraints</h4>
26272630

26282631
<p>
2629-
A type constraint is an <a href="#Interface_types">interface</a> that determines the
2632+
A type constraint is an <a href="#Interface_types">interface</a> that defines the
26302633
set of permissible type arguments for the respective type parameter and controls the
26312634
operations supported by values of that type parameter.
26322635
</p>

0 commit comments

Comments
 (0)