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

Error if field type and method have the same name #170

Open
vadimalekseev opened this issue Mar 24, 2022 · 3 comments
Open

Error if field type and method have the same name #170

vadimalekseev opened this issue Mar 24, 2022 · 3 comments

Comments

@vadimalekseev
Copy link

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'

@matryer
Copy link
Owner

matryer commented Mar 31, 2022

Moq creates ___Func versions of the fields, so this clashes. As a workaround, you could name the field differently?

@vadimalekseev
Copy link
Author

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?

@breml
Copy link
Contributor

breml commented Apr 9, 2022

I think @aleksvdim has a valid point here. I see to following options to resolve this:

  1. Provide a flag in moq, that allows to alter the suffix used to create the field names (e.g. moq -suffix MoqFunc would generate ____MoqFunc
  2. 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.
  3. 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.

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

3 participants