summaryrefslogtreecommitdiff
path: root/vendor/github.com/golang/mock/mockgen/tests/generated_identifier_conflict/README.md
blob: ffb5f9f01a99410b806c12998761847493fa5fd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
The generated mock methods use some hardcoded variable/receiver names that can
have conflicts with the argument names that are defined by the code for which
the mock is generated when using the source generation method.

Example:

```go
type Example interface {
	Method(_m, _mr, m, mr int)
}
```

```go
// Method mocks base method
func (_m *MockExample) Method(_m int, _mr int, m int, mr int) {
	_m.ctrl.Call(_m, "Method", _m, _mr, m, mr)
}
```

In the above example one of the interface method parameters is called `_m`
but unfortunately the generated receiver name is also called `_m` so the
mock code won't compile.

The generator has to make sure that generated identifiers (e.g.: the receiver
names) are always different from the arg names that might come from external
sources.