From: Robert Griesemer Date: Thu, 25 Sep 2014 19:49:42 +0000 (-0700) Subject: spec: clarify embedding of interfaces X-Git-Tag: go1.4beta1~289 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=bb29c5a1ed872b770ff5203d8a0109a49e6d1dba;p=gostls13.git spec: clarify embedding of interfaces Fixes #7886. LGTM=iant, r, rsc R=r, iant, rsc, ken CC=golang-codereviews https://golang.org/cl/149010043 --- diff --git a/doc/go_spec.html b/doc/go_spec.html index 7d86ca863a..e0ed7e7b74 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -1154,11 +1154,11 @@ interface{}

Similarly, consider this interface specification, which appears within a type declaration -to define an interface called Lock: +to define an interface called Locker:

-type Lock interface {
+type Locker interface {
 	Lock()
 	Unlock()
 }
@@ -1174,28 +1174,35 @@ func (p T) Unlock() { … }
 

-they implement the Lock interface as well +they implement the Locker interface as well as the File interface.

+

-An interface may use an interface type name T -in place of a method specification. -The effect, called embedding an interface, -is equivalent to enumerating the methods of T explicitly -in the interface. +An interface T may use a (possibly qualified) interface type +name E in place of a method specification. This is called +embedding interface E in T; it adds +all (exported and non-exported) methods of E to the interface +T.

-type ReadWrite interface {
+type ReadWriter interface {
 	Read(b Buffer) bool
 	Write(b Buffer) bool
 }
 
 type File interface {
-	ReadWrite  // same as enumerating the methods in ReadWrite
-	Lock       // same as enumerating the methods in Lock
+	ReadWriter  // same as adding the methods of ReadWriter
+	Locker      // same as adding the methods of Locker
 	Close()
 }
+
+type LockedFile interface {
+	Locker
+	File        // illegal: Lock, Unlock not unique
+	Lock()      // illegal: Lock not unique
+}