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

Will panic if access interface method's parameters #115

Open
grovecai opened this issue Oct 27, 2022 · 1 comment
Open

Will panic if access interface method's parameters #115

grovecai opened this issue Oct 27, 2022 · 1 comment

Comments

@grovecai
Copy link

Go Version: go version go1.18.2 darwin/amd64
MacOS version: macOS Monterey, version 12.3.1, Intel
gomockey version: v2.9.0

Sample code

package go_play

import (
	"fmt"
	"github.com/agiledragon/gomonkey/v2"
	"testing"
)

type Dummy interface {
	Get(a string) string
}

type dummy struct {
}

func (t *dummy) Get(a string) string {
	return "prefix: " + a
}

func Test_go(t *testing.T) {
	patches := gomonkey.NewPatches()
	defer patches.Reset()
	patches.ApplyMethod(&dummy{}, "Get", func(_ Dummy, in string) string {
		fmt.Println("IN: " + in) //Panic
		return "dummy"
	})
	ret := (&dummy{}).Get("hello")
	fmt.Printf("Actual: " + ret)
}

@grovecai
Copy link
Author

Panic with -gcflags=all=-l
No Panic with -gcflags=-l, but fmt.Println("IN: " + in) not works as expected, only output IN:

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

No branches or pull requests

1 participant