1
0
mirror of https://github.com/golang/go synced 2024-11-23 11:00:08 -07:00
go/doc
Robert Griesemer 40818cfe1c spec: method selectors don't auto-deref named pointer types
Language clarification.

The existing rules for selector expressions imply
automatic dereferencing of pointers to struct fields.
They also implied automatic dereferencing of selectors
denoting methods. In almost all cases, such automatic
dereferencing does indeed take place for methods but the
reason is not the selector rules but the fact that method
sets include both methods with T and *T receivers; so for
a *T actual receiver, a method expecting a formal T
receiver, also accepts a *T (and the invocation or method
value expression is the reason for the auto-derefering).

However, the rules as stated so far implied that even in
case of a variable p of named pointer type P, a selector
expression p.f would always be shorthand for (*p).f. This
is true for field selectors f, but cannot be true for
method selectors since a named pointer type always has an
empty method set.

Named pointer types may never appear as anonymous field
types (and method receivers, for that matter), so this
only applies to variables declared of a named pointer
type. This is exceedingly rare and perhaps shouldn't be
permitted in the first place (but we cannot change that).

Amended the selector rules to make auto-deref of values
of named pointer types an exception to the general rules
and added corresponding examples with explanations.

Both gc and gccgo have a bug where they do auto-deref
pointers of named types in method selectors where they
should not:

See http://play.golang.org/p/c6VhjcIVdM , line 45.

Fixes #5769.
Fixes #8989.

LGTM=r, rsc
R=r, rsc, iant, ken
CC=golang-codereviews
https://golang.org/cl/168790043
2014-11-11 13:19:47 -08:00
..
articles all: use golang.org/x/... import paths 2014-11-10 09:15:57 +11:00
codewalk doc: fix typo in sharemem codewalk 2014-05-21 14:34:20 -07:00
devel doc: document go1.3.3 2014-10-01 08:30:51 +10:00
gopher doc/gopher: add jpgs of the 5th anniversary image 2014-11-11 23:46:20 +11:00
play doc: remove godocs.js and playground.js from core repo 2013-08-01 15:09:18 +10:00
progs doc/progs: don't try building cgo tests if CGO_ENABLED=0 2013-10-11 08:55:13 -07:00
asm.html doc/asm: explain coordination with garbage collector 2014-10-28 15:51:06 -04:00
cmd.html all: use golang.org/x/... import paths 2014-11-10 09:15:57 +11:00
code.html all: use golang.org/x/... import paths 2014-11-10 09:15:57 +11:00
contrib.html doc: drop scheme from links that are known to support HTTPS 2014-07-25 10:28:39 +10:00
contribute.html all: use golang.org/x/... import paths 2014-11-10 09:15:57 +11:00
debugging_with_gdb.html build: adjustments for move from src/pkg to src 2014-09-08 00:06:45 -04:00
docs.html doc: drop scheme from links that are known to support HTTPS 2014-07-25 10:28:39 +10:00
effective_go.html build: adjustments for move from src/pkg to src 2014-09-08 00:06:45 -04:00
gccgo_contribute.html build: adjustments for move from src/pkg to src 2014-09-08 00:06:45 -04:00
gccgo_install.html gccgo_install.html: the 4.9 release series supports Go 1.2 2014-10-22 20:41:13 -07:00
go1.1.html doc: drop scheme from links that are known to support HTTPS 2014-07-25 10:28:39 +10:00
go1.2.html doc: drop scheme from links that are known to support HTTPS 2014-07-25 10:28:39 +10:00
go1.3.html doc: document new ParseMultipartForm behavior 2014-08-07 15:42:06 +10:00
go1.4.html doc: update go1.4.html's minor library changes. 2014-11-11 16:06:47 +11:00
go1.html doc: link directly to https://golang.org/dl/ 2014-09-12 09:15:58 +10:00
go1compat.html all: use golang.org/x/... import paths 2014-11-10 09:15:57 +11:00
go_faq.html all: use golang.org/x/... import paths 2014-11-10 09:15:57 +11:00
go_mem.html doc/go_mem.html: don't be clever 2014-10-27 17:08:50 -07:00
go_spec.html spec: method selectors don't auto-deref named pointer types 2014-11-11 13:19:47 -08:00
go-logo-black.png doc: pngcrush and remove old, unused images 2012-03-08 14:18:28 +11:00
go-logo-blue.png doc: pngcrush and remove old, unused images 2012-03-08 14:18:28 +11:00
go-logo-white.png doc: pngcrush and remove old, unused images 2012-03-08 14:18:28 +11:00
help.html doc: drop scheme from links that are known to support HTTPS 2014-07-25 10:28:39 +10:00
ie.css
install-source.html all: use golang.org/x/... import paths 2014-11-10 09:15:57 +11:00
install.html doc: link directly to https://golang.org/dl/ 2014-09-12 09:15:58 +10:00
logo-153x55.png doc: pngcrush and remove old, unused images 2012-03-08 14:18:28 +11:00
root.html doc: drop scheme from links that are known to support HTTPS 2014-07-25 10:28:39 +10:00
share.png godoc: change link styles, add 'pop out' button 2012-03-13 11:00:11 +11:00
sieve.gif
tos.html doc: drop scheme from links that are known to support HTTPS 2014-07-25 10:28:39 +10:00