Skip to content

Commit

Permalink
spec: clarify type term restriction for type parameters
Browse files Browse the repository at this point in the history
Be clear that the type of a term (not the term itself, which may
be of the form ~P) cannot be a type parameter.

For #50420.

Change-Id: I388d57be0618393d7ebe2c74ec04c1ebe3f33f7d
Reviewed-on: https://go-review.googlesource.com/c/go/+/396915
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
  • Loading branch information
griesemer committed Mar 31, 2022
1 parent 81f1cc5 commit ea85873
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions doc/go_spec.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--{
"Title": "The Go Programming Language Specification",
"Subtitle": "Version of March 10, 2022",
"Subtitle": "Version of March 30, 2022",
"Path": "/ref/spec"
}-->

Expand Down Expand Up @@ -1454,15 +1454,16 @@ <h4 id="General_interfaces">General interfaces</h4>
</pre>

<p>
In a union, a term cannot be a <a href="#Type_parameter_declarations">type parameter</a>, and the type sets of all
The type <code>T</code> in a term of the form <code>T</code> or <code>~T</code> cannot
be a <a href="#Type_parameter_declarations">type parameter</a>, 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 <code>P</code>:
</p>

<pre>
interface {
P // illegal: P is a type parameter
int | P // illegal: P is a type parameter
int | ~P // illegal: P is a type parameter
~int | MyInt // illegal: the type sets for ~int and MyInt are not disjoint (~int includes MyInt)
float32 | Float // overlapping type sets but Float is an interface
}
Expand Down Expand Up @@ -4195,7 +4196,7 @@ <h3 id="Instantiations">Instantiations</h3>
<p>
For a generic function, type arguments may be provided explicitly, or they
may be partially or completely <a href="#Type_inference">inferred</a>.
A generic function that is is <i>not</i> <a href="#Calls">called</a> requires a
A generic function that is <i>not</i> <a href="#Calls">called</a> requires a
type argument list for instantiation; if the list is partial, all
remaining type arguments must be inferrable.
A generic function that is called may provide a (possibly partial) type
Expand Down

0 comments on commit ea85873

Please sign in to comment.