Descriptionspec: 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/ #MessagesTotal messages: 6
|