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:
Robert Griesemer 2021-11-28 14:17:11 -08:00
parent 4325c37d67
commit 37a5d720d4

View file

@ -1,6 +1,6 @@
<!--{
"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"
}-->
@ -1971,39 +1971,38 @@ x T x is not representable by a value of T because
<p>
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
interface definition in terms of the form <code>T</code>, <code>~T</code>,
or in unions of such terms.
</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>
<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>The set of specific types of a non-empty interface is the intersection
of the specific types of its interface elements.
<li>For an interface with type elements, 𝑆 is the intersection
of the specific types of its type elements.
</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>The set of specific types of a non-interface type term <code>T</code>
or <code>~T</code> is the set consisting of the type <code>T</code>.
</li>
<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>For 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>
</ul>
<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>
@ -2019,6 +2018,8 @@ interface{ int } // int
interface{ ~string } // string
interface{ int|~string } // int, string
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)
</pre>
@ -3980,7 +3981,8 @@ pt.Scale(3.5) // method call with receiver pt
<p>
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>
@ -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>.
</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>.
</li>
</ul>