Mock method parameter shadows unexported types
- Dominant language
- Go
- Stars
- 2.2k
- Forks
- 135
- Avg merge
- 11d 6h
- Merged PRs (30d)
- 1
Description
Please consider the following snippet:
```go
package main
type s struct{}
//go:generate moq -out i_test.go . i
type i interface {
m(s s)
}
```
moq generates:
```go
// 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.
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the interface and go:generate command from the issue, then trace the generator entry point that emits mock method parameters and call-info structs. Add a regression case for the unexported type name and verify that the generated Go compiles without the parameter shadowing its type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100