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

Mock method parameter shadows unexported types #216

Open
bitflipp opened this issue Apr 16, 2024 · 0 comments
Open

Mock method parameter shadows unexported types #216

bitflipp opened this issue Apr 16, 2024 · 0 comments

Comments

@bitflipp
Copy link

Please consider the following snippet:

package main

type s struct{}

//go:generate moq -out i_test.go . i
type i interface {
	m(s s)
}

moq generates:

// m calls mFunc.
func (mock *iMock) m(s s) {            // Type s is shadowed.
	if mock.mFunc == nil {
		panic("iMock.mFunc: method is nil but i.m was just called")
	}
	callInfo := struct {
		S s                    // Compiler error: s (variable of type s) is not a type.
	}{
		S: s,
	}
	mock.lockm.Lock()
	mock.calls.m = append(mock.calls.m, callInfo)
	mock.lockm.Unlock()
	mock.mFunc(s)
}

This may (and arguably should) be remedied by changing the interface method to m(somethingDescriptive s), yet it's an invalid output generated from a valid input.

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