Commit bb3e2117 authored by Robert Griesemer's avatar Robert Griesemer

spec: clarify rules for receiver base types

The spec currently provides a syntactic rule for receiver base types,
and a strict reading of those rules prohibits the use of type aliases
referring to pointer types as receiver types.

This strict interpretation breaks an assumed rule for aliases, which
is that a type literal can always be replaced by an alias denoting
that literal.

Furthermore, cmd/compile always accepted this new formulation of the
receiver type rules and so this change will simply validate what has
been implemented all along.

Fixes #27995.

Change-Id: I032289c926a4f070d6f7795431d86635fe64d907
Reviewed-on: https://go-review.googlesource.com/c/142757Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: 's avatarRob Pike <r@golang.org>
Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
parent dc75744f
<!--{
"Title": "The Go Programming Language Specification",
"Subtitle": "Version of October 8, 2018",
"Subtitle": "Version of October 17, 2018",
"Path": "/ref/spec"
}-->
......@@ -2202,11 +2202,11 @@ Receiver = Parameters .
<p>
The receiver is specified via an extra parameter section preceding the method
name. That parameter section must declare a single non-variadic 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 <a href="#Type_definitions">defined</a> in the same package as the method.
The method is said to be <i>bound</i> to the base type and the method name
Its type must be a <a href="#Type_definitions">defined</a> type <code>T</code> or a
pointer to a defined type <code>T</code>. <code>T</code> is called the receiver
<i>base type</i>. A receiver base type cannot be a pointer or interface type and
it must be defined in the same package as the method.
The method is said to be <i>bound</i> to its receiver base type and the method name
is visible only within <a href="#Selectors">selectors</a> for type <code>T</code>
or <code>*T</code>.
</p>
......@@ -2226,7 +2226,7 @@ the non-blank method and field names must be distinct.
</p>
<p>
Given type <code>Point</code>, the declarations
Given defined type <code>Point</code>, the declarations
</p>
<pre>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment