I would expect this program to work:
package main
import "reflect"
type T int
func (*T) M() {}
func main() {
var t T
v := reflect.ValueOf(&t).Elem()
v.MethodByName("M").Call(nil)
}
Currently, it produces panic: reflect: call of reflect.Value.Call on zero Value panic, because M is not in the method set of T (only *T).
This seems overly strict to me. The Go spec allows calling t.M() where t is an addressable value of type T; it's just implicitly executed as (&t).M(). I would expect package reflect to handle this implicit dereference, but it does not.
For comparison, the spec also allows an implicit dereference to call value-receiver methods on pointer types, and package reflect does perform this implicit dereference.
/cc @ianlancetaylor @dsnet
I would expect this program to work:
Currently, it produces
panic: reflect: call of reflect.Value.Call on zero Valuepanic, becauseMis not in the method set ofT(only*T).This seems overly strict to me. The Go spec allows calling
t.M()where t is an addressable value of type T; it's just implicitly executed as(&t).M(). I would expect package reflect to handle this implicit dereference, but it does not.For comparison, the spec also allows an implicit dereference to call value-receiver methods on pointer types, and package reflect does perform this implicit dereference.
/cc @ianlancetaylor @dsnet