Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(299)

Issue 168790043: code review 168790043: spec: method selectors don't auto-deref named pointer types (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
9 years, 6 months ago by gri
Modified:
9 years, 5 months ago
Reviewers:
r, rsc
CC:
r, rsc, iant, ken2, golang-codereviews
Visibility:
Public.

Description

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 issue 5769. Fixes issue 8989.

Patch Set 1 #

Patch Set 2 : diff -r 7596da5133097c73aff139b9a43512aa8ae00095 https://code.google.com/p/go/ #

Patch Set 3 : diff -r 7596da5133097c73aff139b9a43512aa8ae00095 https://code.google.com/p/go/ #

Total comments: 2

Patch Set 4 : diff -r 53ebc70d4e9f843cb718f173e3225e9a0fc121e2 https://code.google.com/p/go #

Total comments: 2

Patch Set 5 : diff -r 23e7f4cc31cd8df33166644ae71284fa700aa9ff https://code.google.com/p/go/ #

Patch Set 6 : diff -r 087c5e6f289ca6fee175c33b3c6afa4b10b02479 https://code.google.com/p/go/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+44 lines, -28 lines) Patch
M doc/go_spec.html View 1 2 3 4 5 6 chunks +44 lines, -28 lines 0 comments Download

Messages

Total messages: 6
gri
Hello r@golang.org, rsc@golang.org, iant@golang.org, ken@golang.org (cc: golang-codereviews@googlegroups.com), I'd like you to review this change to ...
9 years, 6 months ago (2014-10-29 18:54:31 UTC) #1
r
LGTM https://codereview.appspot.com/168790043/diff/40001/doc/go_spec.html File doc/go_spec.html (right): https://codereview.appspot.com/168790043/diff/40001/doc/go_spec.html#newcode2524 doc/go_spec.html:2524: where <code>T</code> is not pointer or interface type, ...
9 years, 5 months ago (2014-11-01 14:14:50 UTC) #2
gri
PTAL https://codereview.appspot.com/168790043/diff/40001/doc/go_spec.html File doc/go_spec.html (right): https://codereview.appspot.com/168790043/diff/40001/doc/go_spec.html#newcode2524 doc/go_spec.html:2524: where <code>T</code> is not pointer or interface type, ...
9 years, 5 months ago (2014-11-03 05:19:01 UTC) #3
rsc
LGTM https://codereview.appspot.com/168790043/diff/60001/doc/go_spec.html File doc/go_spec.html (right): https://codereview.appspot.com/168790043/diff/60001/doc/go_spec.html#newcode2561 doc/go_spec.html:2561: As an exception, if the type of <code>x</code> ...
9 years, 5 months ago (2014-11-07 00:32:32 UTC) #4
gri
https://codereview.appspot.com/168790043/diff/60001/doc/go_spec.html File doc/go_spec.html (right): https://codereview.appspot.com/168790043/diff/60001/doc/go_spec.html#newcode2561 doc/go_spec.html:2561: As an exception, if the type of <code>x</code> is ...
9 years, 5 months ago (2014-11-07 23:21:53 UTC) #5
gri
9 years, 5 months ago (2014-11-11 21:19:54 UTC) #6
*** Submitted as https://code.google.com/p/go/source/detail?r=d51282ff68c0 ***

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 issue 5769.
Fixes issue 8989.

LGTM=r, rsc
R=r, rsc, iant, ken
CC=golang-codereviews
https://codereview.appspot.com/168790043
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b