mirror of
https://github.com/golang/go
synced 2024-10-14 11:53:56 +00:00
spec: clarify type term restriction for type parameters
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>
This commit is contained in:
parent
81f1cc52ab
commit
ea858734be
|
@ -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"
|
||||
}-->
|
||||
|
||||
|
@ -1454,7 +1454,8 @@ type Float interface {
|
|||
</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>
|
||||
|
@ -1462,7 +1463,7 @@ Given a type parameter <code>P</code>:
|
|||
<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
|
||||
}
|
||||
|
@ -4195,7 +4196,7 @@ type parameter list type arguments after substitution
|
|||
<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
|
||||
|
|
Loading…
Reference in a new issue