Hey Gophers,

I've run in to an interesting case regarding Method Sets that makes me 
wonder whether it should be disallowed by the spec[1]. Before opening an 
issue on GitHub I thought I'd reach out here to get some clarifications as 
I may be misreading the spec.

Based on my understanding of method sets, a variable with the type *T should 
have a method set that contains methods on T and *T, while a variable of 
type T should only have methods with a receiver for T in the method set. To 
me this translates that if my variable is not a pointer type it should not 
be able to call a method that's receiving a pointer type.

However, I've observed that to not be the case. If I have a variable of 
type T, I am able to invoke methods that are receiving *T[2]. Should that 
be permitted by the spec? It adds some inconsistency because I am able to 
invoke the method on my variable, but the variable won't satisfy an 
interface that has that method included[3]. I think it's acceptable that 
the interface isn't satisfied, but what makes it so that invoking the 
method directly is permitted?

Cheers!
-Tim

[1] https://golang.org/ref/spec#Method_sets
[2] https://play.golang.org/p/-OMAnD7U0Vl
[3] https://play.golang.org/p/uP0_eMYqYEe

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to