From: Robert Griesemer Date: Thu, 22 May 2014 19:23:25 +0000 (-0700) Subject: spec: explicitly disallow blank methods in interface types X-Git-Tag: go1.3rc1~50 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2c83f1eaf93c3d1891588e82b4fd4e761d161fdd;p=gostls13.git spec: explicitly disallow blank methods in interface types The spec was unclear about whether blank methods should be permitted in interface types. gccgo permits at most one, gc crashes if there are more than one, go/types permits at most one. Discussion: Since method sets of non-interface types never contain methods with blank names (blank methods are never declared), it is impossible to satisfy an interface with a blank method. It is possible to declare variables of assignable interface types (but not necessarily identical types) containing blank methods, and assign those variables to each other, but the values of those variables can only be nil. There appear to be two "reasonable" alternatives: 1) Permit at most one blank method (since method names must be unique), and consider it part of the interface. This is what appears to happen now, with corner-case bugs. Such interfaces can never be implemented. 2) Permit arbitrary many blank methods but ignore them. This appears to be closer to the handling of blank identifiers in declarations. However, an interface type literal is not a declaration (it's a type literal). Also, for struct types, blank identifiers are not ignored; so the analogy with declarations is flawed. Both these alternatives don't seem to add any benefit and are likely (if only slightly) more complicated to explain and implement than disallowing blank methods in interfaces altogether. Fixes #6604. LGTM=r, rsc, iant R=r, rsc, ken, iant CC=golang-codereviews https://golang.org/cl/99410046 --- diff --git a/doc/go_spec.html b/doc/go_spec.html index 4c80f39d4c..11f6a90e63 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -696,19 +696,19 @@ and T4 is []T1.

Method sets

-A type may have a method set associated with it -(§Interface types, §Method declarations). +A type may have a method set associated with it. The method set of an interface type is its interface. -The method set of any other type T -consists of all methods with receiver type T. -The method set of the corresponding pointer type *T -is the set of all methods with receiver *T or T +The method set of any other type T consists of all +methods declared with receiver type T. +The method set of the corresponding pointer type *T +is the set of all methods declared with receiver *T or T (that is, it also contains the method set of T). Further rules apply to structs containing anonymous fields, as described in the section on struct types. Any other type has an empty method set. In a method set, each method must have a -unique method name. +unique +non-blank method name.

@@ -818,8 +818,8 @@ ElementType = Type .

-The length is part of the array's type; it must evaluate to a non- -negative constant representable by a value +The length is part of the array's type; it must evaluate to a +non-negative constant representable by a value of type int. The length of array a can be discovered using the built-in function len. @@ -1109,7 +1109,8 @@ InterfaceTypeName = TypeName .

As with all method sets, in an interface type, each method must have a -unique name. +unique +non-blank name.