• Robert Griesemer's avatar
    spec: method selectors don't auto-deref named pointer types · 40818cfe
    Robert Griesemer authored
    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
    40818cfe
Name
Last commit
Last update
..
articles Loading commit data...
codewalk Loading commit data...
devel Loading commit data...
gopher Loading commit data...
play Loading commit data...
progs Loading commit data...
asm.html Loading commit data...
cmd.html Loading commit data...
code.html Loading commit data...
contrib.html Loading commit data...
contribute.html Loading commit data...
debugging_with_gdb.html Loading commit data...
docs.html Loading commit data...
effective_go.html Loading commit data...
gccgo_contribute.html Loading commit data...
gccgo_install.html Loading commit data...
go-logo-black.png Loading commit data...
go-logo-blue.png Loading commit data...
go-logo-white.png Loading commit data...
go1.1.html Loading commit data...
go1.2.html Loading commit data...
go1.3.html Loading commit data...
go1.4.html Loading commit data...
go1.html Loading commit data...
go1compat.html Loading commit data...
go_faq.html Loading commit data...
go_mem.html Loading commit data...
go_spec.html Loading commit data...
help.html Loading commit data...
ie.css Loading commit data...
install-source.html Loading commit data...
install.html Loading commit data...
logo-153x55.png Loading commit data...
root.html Loading commit data...
share.png Loading commit data...
sieve.gif Loading commit data...
tos.html Loading commit data...