Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't implement receiver method #1535

Open
introspection3 opened this issue Apr 2, 2023 · 1 comment
Open

can't implement receiver method #1535

introspection3 opened this issue Apr 2, 2023 · 1 comment

Comments

@introspection3
Copy link

The following program sample.go triggers an unexpected result

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)
}

Expected result

1

Got

0

Yaegi Version

v0.15.1

Additional Notes

too sad,sir....

@mvertes
Copy link
Member

mvertes commented Apr 20, 2023

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).

@mvertes mvertes changed the title can't implement recevier method can't implement receiver method Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants