mirror of
https://github.com/golang/go
synced 2024-09-15 22:20:06 +00:00
spec: corrections to various sections
- fix definition of "specific types" and add more examples - state that a parameterized function must be instantiated when used as a function value - remove duplicate word ("can can" -> "can") Thanks to @danscales for finding these. Change-Id: Ideb41efc35a3e67694d3bc97e462454feae37c44 Reviewed-on: https://go-review.googlesource.com/c/go/+/367394 Trust: Robert Griesemer <gri@golang.org> Trust: Dan Scales <danscales@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
This commit is contained in:
parent
4325c37d67
commit
37a5d720d4
|
@ -1,6 +1,6 @@
|
||||||
<!--{
|
<!--{
|
||||||
"Title": "The Go Programming Language Specification - Go 1.18 Draft (incomplete)",
|
"Title": "The Go Programming Language Specification - Go 1.18 Draft (incomplete)",
|
||||||
"Subtitle": "Version of Nov 24, 2021",
|
"Subtitle": "Version of Nov 29, 2021",
|
||||||
"Path": "/ref/spec"
|
"Path": "/ref/spec"
|
||||||
}-->
|
}-->
|
||||||
|
|
||||||
|
@ -1971,39 +1971,38 @@ x T x is not representable by a value of T because
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
An interface specification which contains <a href="#Interface_types">type elements</a>
|
An interface specification which contains <a href="#Interface_types">type elements</a>
|
||||||
that are not interface types defines a (possibly empty) set of <i>specific types</i>.
|
defines a (possibly empty) set of <i>specific types</i>.
|
||||||
Loosely speaking, these are the types <code>T</code> that appear in the
|
Loosely speaking, these are the types <code>T</code> that appear in the
|
||||||
interface definition in terms of the form <code>T</code>, <code>~T</code>,
|
interface definition in terms of the form <code>T</code>, <code>~T</code>,
|
||||||
or in unions of such terms.
|
or in unions of such terms.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
More precisely, for a given interface, the set of specific types is defined as follows:
|
More precisely, for a given interface, the set 𝑆 of specific types is defined as follows:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li>The set of specific types of the empty interface is the empty set.
|
<li>For an interface with no type elements, 𝑆 is the empty set.
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>The set of specific types of a non-empty interface is the intersection
|
<li>For an interface with type elements, 𝑆 is the intersection
|
||||||
of the specific types of its interface elements.
|
of the specific types of its type elements.
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>The set of specific types of a method specification is the empty set.
|
<li>For a non-interface type term <code>T</code>
|
||||||
|
or <code>~T</code>, 𝑆 is the set consisting of the type <code>T</code>.
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>The set of specific types of a non-interface type term <code>T</code>
|
<li>For a <i>union</i> of terms
|
||||||
or <code>~T</code> is the set consisting of the type <code>T</code>.
|
<code>t<sub>1</sub>|t<sub>2</sub>|…|t<sub>n</sub></code>,
|
||||||
</li>
|
𝑆 is the union of the specific types of the terms.
|
||||||
|
|
||||||
<li>The set of specific types of a <i>union</i> of terms
|
|
||||||
<code>t<sub>1</sub>|t<sub>2</sub>|…|t<sub>n</sub></code>
|
|
||||||
is the union of the specific types of the terms.
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
If the set of specific types is empty, the interface has <i>no specific types</i>.
|
If 𝑆 is empty, the interface has <i>no specific types</i>.
|
||||||
|
An interface may have specific types even if its <a href="#Interface_types">type set</a>
|
||||||
|
is empty.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
@ -2019,6 +2018,8 @@ interface{ int } // int
|
||||||
interface{ ~string } // string
|
interface{ ~string } // string
|
||||||
interface{ int|~string } // int, string
|
interface{ int|~string } // int, string
|
||||||
interface{ Celsius|Kelvin } // Celsius, Kelvin
|
interface{ Celsius|Kelvin } // Celsius, Kelvin
|
||||||
|
interface{ int; m() } // int (but type set is empty because int has no method m)
|
||||||
|
interface{ int; any } // no specific types (intersection is empty)
|
||||||
interface{ int; string } // no specific types (intersection is empty)
|
interface{ int; string } // no specific types (intersection is empty)
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
@ -3980,7 +3981,8 @@ pt.Scale(3.5) // method call with receiver pt
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
If <code>f</code> denotes a parameterized function, it must be
|
If <code>f</code> denotes a parameterized function, it must be
|
||||||
<a href="#Instantiations">instantiated</a> before it can be called.
|
<a href="#Instantiations">instantiated</a> before it can be called
|
||||||
|
or used as a function value.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
@ -4807,7 +4809,7 @@ Only <code>V</code> is a type parameter and a value of each
|
||||||
specific type of <code>V</code> can be converted to <code>T</code>.
|
specific type of <code>V</code> can be converted to <code>T</code>.
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
Only <code>T</code> is a type parameter and <code>x</code> can can be converted to each
|
Only <code>T</code> is a type parameter and <code>x</code> can be converted to each
|
||||||
specific type of <code>T</code>.
|
specific type of <code>T</code>.
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Reference in a new issue