On Fri, Aug 28, 2015 at 3:50 PM, <
gerald.r...@gmail.com> wrote:
> Yes, but that really isn't at the crux of the problem or the fix.
>
> The strange looking thing is that by adding an '&' in the var assignment,
> sync.Locker in the method set Y suddenly accepts the structure X as
> implementing Y independent of whether the embedded field sync.Mutex is
> direct or pointer.
>
> Requiring an embedded pointer field to satisfy the pointer-receiver
> requirement of a method set member seems logically correlated. The
> obliteration of that correlation by a distant var assignment (spooky action
> at a distance) is, well, strange. Guessing it has something to do with the
> heuristics of the type-inferencing system, but a guess is far shy of a
> comfortable understanding.
There is no spooky at a distance action. The decision about whether a
type implements an interface is based on the type's method set.
http://golang.org/ref/spec#Method_sets
People often get confused about Method sets because of how the dot
selector will automatically take the address of receiver, so they
assume that T and *T both have the same method set.
http://golang.org/ref/spec#Selectors
The difference matter with interfaces because a value isn't
addressable while it's in an interface.
So if you want to call a method with a pointer receiver on a value in
an interface then the value must a pointer because the dot selector
can't just get you the address of that value.