Skip to content

Commit 30501bb

Browse files
committed
spec: introduce notion of basic interface, misc. fine-tuning
A basic interface is a classical Go interface containing only methods or embedding basic interfaces. Use this to simplify rule about what interfaces may be used where. The term "basic interface" will also be useful when talking about various interfaces in general. Fix rule restricting union terms: as it was written it also excluded interface terms with non-empty method sets due to embedded non-interface types with methods. Split the large section on interfaces into three smaller pieces by introducing section titles. Change-Id: I142a4d5609eb48aaa0f7800b5b85c1d6c0703fcb Reviewed-on: https://go-review.googlesource.com/c/go/+/384994 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
1 parent ca3fae1 commit 30501bb

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

doc/go_spec.html

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,11 +1226,15 @@ <h3 id="Interface_types">Interface types</h3>
12261226
A type term is either a single type or a single underlying type.
12271227
</p>
12281228

1229+
<h4 id="Basic_interfaces">Basic interfaces</h4>
1230+
12291231
<p>
12301232
In its most basic form an interface specifies a (possibly empty) list of methods.
12311233
The type set defined by such an interface is the set of types which implement all of
12321234
those methods, and the corresponding <a href="#Method_sets">method set</a> consists
12331235
exactly of the methods specified by the interface.
1236+
Interfaces whose type sets can be defined entirely by a list of methods are called
1237+
<i>basic interfaces.</i>
12341238
</p>
12351239

12361240
<pre>
@@ -1315,6 +1319,8 @@ <h3 id="Interface_types">Interface types</h3>
13151319
as the <code>File</code> interface.
13161320
</p>
13171321

1322+
<h4 id="Embedded_interfaces">Embedded interfaces</h4>
1323+
13181324
<p>
13191325
In a slightly more general form
13201326
an interface <code>T</code> may use a (possibly qualified) interface type
@@ -1359,8 +1365,10 @@ <h3 id="Interface_types">Interface types</h3>
13591365
}
13601366
</pre>
13611367

1368+
<h4 id="Generenal_interfaces">General interfaces</h4>
1369+
13621370
<p>
1363-
Finally, in their most general form, an interface element may also be an arbitrary type term
1371+
In their most general form, an interface element may also be an arbitrary type term
13641372
<code>T</code>, or a term of the form <code>~T</code> specifying the underlying type <code>T</code>,
13651373
or a union of terms <code>t<sub>1</sub>|t<sub>2</sub>|…|t<sub>n</sub></code>.
13661374
Together with method specifications, these elements enable the precise
@@ -1462,21 +1470,21 @@ <h3 id="Interface_types">Interface types</h3>
14621470

14631471
<p>
14641472
Implementation restriction:
1465-
A union with more than one term cannot contain interface types
1466-
with non-empty <a href="#Method_sets">method sets</a> or which
1467-
are or embed the <a href="#Predeclared_identifiers">predeclared identifier</a>
1468-
<code>comparable</code>.
1473+
A union with more than one term cannot contain the
1474+
<a href="#Predeclared_identifiers">predeclared identifier</a> <code>comparable</code>
1475+
or interfaces that specify methods, or embed <code>comparable</code> or interfaces
1476+
that specify methods.
14691477
</p>
14701478

14711479
<p>
1472-
Interfaces that contain non-interface types, terms of the form <code>~T</code>,
1473-
or unions may only be used as type constraints, or as elements of other interfaces used
1474-
as constraints. They cannot be the types of values or variables, or components of other,
1480+
Interfaces that are not <a href="#Basic_interfaces">basic</a> may only be used as type
1481+
constraints, or as elements of other interfaces used as constraints.
1482+
They cannot be the types of values or variables, or components of other,
14751483
non-interface types.
14761484
</p>
14771485

14781486
<pre>
1479-
var x Floats // illegal: Floats is restricted by float32 and float64
1487+
var x Floats // illegal: Floats is not a basic interface
14801488

14811489
var x interface{} = Floats(nil) // illegal
14821490

@@ -1714,7 +1722,7 @@ <h3 id="Underlying_types">Underlying types</h3>
17141722
<h3 id="Core_types">Core types</h3>
17151723

17161724
<p>
1717-
Each non-interface type <code>T</code> has a <i>core</i> type, which is the
1725+
Each non-interface type <code>T</code> has a <i>core type</i>, which is the same as the
17181726
<a href="#Underlying_types">underlying type</a> of <code>T</code>.
17191727
</p>
17201728

@@ -2665,9 +2673,9 @@ <h4 id="Type_constraints">Type constraints</h4>
26652673
</pre>
26662674

26672675
<p>
2668-
If the constraint is an interface literal containing exactly one embedded type element
2669-
<code>interface{E}</code>, in a type parameter list the enclosing <code>interface{ … }</code>
2670-
may be omitted for convenience:
2676+
If the constraint is an interface literal of the form <code>interface{E}</code> where
2677+
<code>E</code> is an embedded type element (not a method), in a type parameter list
2678+
the enclosing <code>interface{ … }</code> may be omitted for convenience:
26712679
</p>
26722680

26732681
<pre>

0 commit comments

Comments
 (0)