moq
                                
                                 moq copied to clipboard
                                
                                    moq copied to clipboard
                            
                            
                            
                        Error if field type and method have the same name
Hey!
When I do go generate ./... I get an error.
package main
//go:generate moq -out mocks/some_iface.go . SomeIface
type SomeIface interface {
	Begin()
	BeginFunc()
}
Error:
Type '*SomeIfaceMock' has both field and method named 'BeginFunc'
Moq creates ___Func versions of the fields, so this clashes. As a workaround, you could name the field differently?
As a workaround, you could name the field differently?
I want to moq the pgx.Pool, https://github.com/jackc/pgx/blob/v4.15.0/pgxpool/conn.go#L83
I cannot name the field differently, except to make my own wrapper. Can we add some checks when generating the code?
I think @aleksvdim has a valid point here. I see to following options to resolve this:
- Provide a flag in moq, that allows to alter the suffix used to create the field names (e.g. moq -suffix MoqFuncwould generate____MoqFunc
- Change the suffix to something, that less likely generates a clash, e.g. MoqFunc(not backwards compatible, so I guess this is not an option.
- Check, if the generated fields have a conflict with one of the methods of the interface. If this is the case, use a different suffix.