From: Robert Griesemer Date: Thu, 15 Aug 2019 00:37:20 +0000 (-0700) Subject: spec: allow embedding overlapping interfaces X-Git-Tag: go1.14beta1~1371 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=bc405df3914e82c9967e029a0235e19ba4461072;p=gostls13.git spec: allow embedding overlapping interfaces Updates #6977. Change-Id: I6eda4be550e7c7ea1e1bac3222850002d90a81a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/190378 Reviewed-by: Rob Pike Reviewed-by: Matthew Dempsky --- diff --git a/doc/go_spec.html b/doc/go_spec.html index 89732fb8f2..4f94b14fa5 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -1244,16 +1244,15 @@ The value of an uninitialized variable of interface type is nil.

-InterfaceType      = "interface" "{" { MethodSpec ";" } "}" .
-MethodSpec         = MethodName Signature | InterfaceTypeName .
+InterfaceType      = "interface" "{" { ( MethodSpec | InterfaceTypeName ) ";" } "}" .
+MethodSpec         = MethodName Signature .
 MethodName         = identifier .
 InterfaceTypeName  = TypeName .
 

-As with all method sets, in an interface type, each method must have a -unique -non-blank name. +An interface type may specify methods explicitly through method specifications, +or it may embed methods of other interfaces through interface type names.

@@ -1265,6 +1264,11 @@ interface {
 }
 
+

+The name of each explicitly specified method must be unique +and not blank. +

+
 interface {
 	String() string
@@ -1280,9 +1284,9 @@ have the method set
 

-func (p T) Read(p []byte) (n int, err error)   { return … }
-func (p T) Write(p []byte) (n int, err error)  { return … }
-func (p T) Close() error                       { return … }
+func (p T) Read(p []byte) (n int, err error)
+func (p T) Write(p []byte) (n int, err error)
+func (p T) Close() error
 

@@ -1332,27 +1336,41 @@ as the File 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. +embedding interface E in T. +The method set of T is the union +of the method sets of T’s explicitly declared methods and of +T’s embedded interfaces.

-type ReadWriter interface {
-	Read(b Buffer) bool
-	Write(b Buffer) bool
+type Reader interface {
+	Read(p []byte) (n int, err error)
+	Close() error
 }
 
-type File interface {
-	ReadWriter  // same as adding the methods of ReadWriter
-	Locker      // same as adding the methods of Locker
-	Close()
+type Writer interface {
+	Write(p []byte) (n int, err error)
+	Close() error
 }
 
-type LockedFile interface {
-	Locker
-	File        // illegal: Lock, Unlock not unique
-	Lock()      // illegal: Lock not unique
+// ReadWriter's methods are Read, Write, and Close.
+type ReadWriter interface {
+	Reader  // includes methods of Reader in ReadWriter's method set
+	Writer  // includes methods of Writer in ReadWriter's method set
+}
+
+ +

+A union of method sets contains the (exported and non-exported) +methods of each method set exactly once, and methods with the +same names must +have identical signatures. +

+ +
+type ReadCloser interface {
+	Reader   // includes methods of Reader in ReadCloser's method set
+	Close()  // illegal: signatures of Reader.Close and Close are different
 }