diff options
author | Robert Griesemer <gri@golang.org> | 2014-06-24 16:25:09 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2014-06-24 16:25:09 -0700 |
commit | 187ee2cf2bfd221d8c03daf69a08adb9ede44c84 (patch) | |
tree | cd5e58610175baf621a539bb7e4699a2e90aaefc /doc/go_spec.html | |
parent | de2feeafdcd41a7ba2ff67299d4ccd33ad2fdf75 (diff) | |
download | go-git-187ee2cf2bfd221d8c03daf69a08adb9ede44c84.tar.gz |
spec: receiver declaration is just a parameter declaration
This CL removes the special syntax for method receivers and
makes it just like other parameters. Instead, the crucial
receiver-specific rules (exactly one receiver, receiver type
must be of the form T or *T) are specified verbally instead
of syntactically.
This is a fully backward-compatible (and minor) syntax
relaxation. As a result, the following syntactic restrictions
(which are completely irrelevant) and which were only in place
for receivers are removed:
a) receiver types cannot be parenthesized
b) receiver parameter lists cannot have a trailing comma
The result of this CL is a simplication of the spec and the
implementation, with no impact on existing (or future) code.
Noteworthy:
- gc already permits a trailing comma at the end of a receiver
declaration:
func (recv T,) m() {}
This is technically a bug with the current spec; this CL will
legalize this notation.
- gccgo produces a misleading error when a trailing comma is used:
error: method has multiple receivers
(even though there's only one receiver)
- Compilers and type-checkers won't need to report errors anymore
if receiver types are parenthesized.
Fixes #4496.
LGTM=iant, rsc
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/101500044
Diffstat (limited to 'doc/go_spec.html')
-rw-r--r-- | doc/go_spec.html | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/doc/go_spec.html b/doc/go_spec.html index baa0ecf40b..ca9e50203e 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ <!--{ "Title": "The Go Programming Language Specification", - "Subtitle": "Version of May 28, 2014", + "Subtitle": "Version of June 24, 2014", "Path": "/ref/spec" }--> @@ -2029,13 +2029,14 @@ and associates the method with the receiver's <i>base type</i>. <pre class="ebnf"> MethodDecl = "func" Receiver MethodName ( Function | Signature ) . -Receiver = "(" [ identifier ] [ "*" ] BaseTypeName ")" . -BaseTypeName = identifier . +Receiver = Parameters . </pre> <p> -The receiver type must be of the form <code>T</code> or <code>*T</code> where -<code>T</code> is a type name. The type denoted by <code>T</code> is called +The receiver is specified via an extra parameter section preceeding the method +name. That parameter section must declare a single parameter, the receiver. +Its type must be of the form <code>T</code> or <code>*T</code> (possibly using +parentheses) where <code>T</code> is a type name. The type denoted by <code>T</code> is called the receiver <i>base type</i>; it must not be a pointer or interface type and it must be declared in the same package as the method. The method is said to be <i>bound</i> to the base type and the method name |