package main
import (
"fmt"
"reflect"
)
type S struct {
x int
}
func (S) M(int) {}
type T struct {
*S
}
func main() {
var v = T{}
t := reflect.TypeOf(v)
fmt.Println(t, "has", t.NumMethod(), "methods:")
for i := 0; i < t.NumMethod(); i++ {
fmt.Print(" method#", i, ": ", t.Method(i).Type, "\n")
}
fmt.Println(reflect.ValueOf(v).Method(0)) // ok
_ = v.M // panic
}
Run okay.
panic.
What version of Go are you using (
go version)?What did you do?
What did you expect to see?
Run okay.
What did you see instead?
panic.
Update: similarly for interface dynamic values