Open introspection3 opened 1 year ago
sample.go
package main import ( "fmt" "reflect" "github.com/traefik/yaegi/interp" ) const src = `package foo type IWoker2 interface { Work(str string) string } type Student struct { } func (s *Student) Work(str string) string { return ("student work" + str) } func GetInstance() interface{}{ return new(Student) } ` func main() { i := interp.New(interp.Options{}) _, err := i.Eval(src) if err != nil { panic(err) } v, err := i.Eval("foo.GetInstance()") if err != nil { panic(err) } fmt.Println(v.Type().Name()) w := v.Interface() count := reflect.ValueOf(w).NumMethod() fmt.Println(count) }
1
0
v0.15.1
too sad,sir....
This is a known limitation. Methods are emulated in yaegi, because Go reflect doesn't implement the creation of interfaces or method values at runtime (golang/go#16522).
The following program
sample.go
triggers an unexpected resultExpected result
Got
Yaegi Version
v0.15.1
Additional Notes
too sad,sir....