Go spec says:
The method set of any other type T consists of all methods with receiver type T. The method set of the corresponding pointer type *T is the set of all methods with receiver *T or T (that is, it also contains the method set of T).
I understand this as: T has its own method set, while *T has it own method set plus the method set of T, because it can dereference receiver *T to T and call the method. Therefore, we can call some method with receiver *T of variable type T.
So I decided to verify my logic:
package main
import (
"fmt"
"reflect"
)
type User struct{}
func (self *User) SayWat() {
fmt.Println(self)
fmt.Println(reflect.TypeOf(self))
fmt.Println("WAT
")
}
func main() {
var user User = User{}
fmt.Println(reflect.TypeOf(user), "
")
user.SayWat()
}
http://play.golang.org/p/xMKuLzUbIf
I am a bit confused. It looks like I can call methods "of *T" on T? I have a bit wider example http://play.golang.org/p/RROPMj534A, which confuses me too. Is there some vice versa type inference?
Am I missing something, or my logic is incorrect?
Thanks!