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

panic when GetMethod on interface{} #19

Closed
Sychorius opened this issue Feb 28, 2023 · 1 comment · Fixed by #20
Closed

panic when GetMethod on interface{} #19

Sychorius opened this issue Feb 28, 2023 · 1 comment · Fixed by #20

Comments

@Sychorius
Copy link
Collaborator

Describe the bug

panic when GetMethod on interface{} with message: reflect: call of reflect.Value.Interface on zero Value

To Reproduce

run this test

type A interface {
	Foo()
}

type a struct {
	A
}

type b struct {
	i int
}

func (*b) Foo() {
	fmt.Println("abc")
}

func NewA() A {
	return &a{A: new(b)}
}

func TestXxx(t *testing.T) {
	mockey.PatchConvey("sample", t, func() {
		obj := NewA()
		mockey.Mock(mockey.GetMethod(obj, "Foo")).Build()
	})
}

Expected behavior

Not panic, mock successfully

Mockey version:

v1.2.0

@Sychorius
Copy link
Collaborator Author

This is because getNestedMethod use reflect.Type not reflect.Value, which loss the interface{} field context.
We will fix it soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant