1
0
mirror of https://github.com/golang/go synced 2024-11-11 23:20:24 -07:00

spec: clarify rules for type set construction of an interface

Be explicit that we always mean non-interface types when we
talk about sets of types.

Also, clarify that the quantification "all non-interface types"
means all such types in all possible programs, not just the
current program.

Per suggestion from Philip Wadler.

Change-Id: Ibc7b5823164e547bfcee85d4e523e58c7c27ac8a
Reviewed-on: https://go-review.googlesource.com/c/go/+/398655
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
This commit is contained in:
Robert Griesemer 2022-03-15 10:15:53 -07:00
parent 104742fdda
commit 0e08b02ac5

View File

@ -1,6 +1,6 @@
<!--{
"Title": "The Go Programming Language Specification",
"Subtitle": "Version of March 30, 2022",
"Subtitle": "Version of April 19, 2022",
"Path": "/ref/spec"
}-->
@ -1278,7 +1278,8 @@ then the <code>File</code> interface is implemented by both <code>S1</code> and
<p>
Every type that is a member of the type set of an interface implements that interface.
Any given type may implement several distinct interfaces.
For instance, all types implement the <i>empty interface</i> which stands for the set of all types:
For instance, all types implement the <i>empty interface</i> which stands for the set
of all (non-interface) types:
</p>
<pre>
@ -1380,7 +1381,7 @@ definition of an interface's type set as follows:
of its interface elements.
</li>
<li>The type set of a method specification is the set of types
<li>The type set of a method specification is the set of all non-interface types
whose method sets include that method.
</li>
@ -1389,7 +1390,7 @@ definition of an interface's type set as follows:
</li>
<li>The type set of a term of the form <code>~T</code>
is the set of types whose underlying type is <code>T</code>.
is the set of all types whose underlying type is <code>T</code>.
</li>
<li>The type set of a <i>union</i> of terms
@ -1398,6 +1399,15 @@ definition of an interface's type set as follows:
</li>
</ul>
<p>
The quantification "the set of all non-interface types" refers not just to all (non-interface)
types declared in the program at hand, but all possible types in all possible programs, and
hence is infinite.
Similarly, given the set of all non-interface types that implement a particular method, the
intersection of the method sets of those types will contain exactly that method, even if all
types in the program at hand always pair that method with another method.
</p>
<p>
By construction, an interface's type set never contains an interface type.
</p>