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

Generated code is invalid when only some return parameters are named #533

Closed
1 of 5 tasks
viswajithiii opened this issue Jan 25, 2023 · 2 comments · Fixed by #534
Closed
1 of 5 tasks

Generated code is invalid when only some return parameters are named #533

viswajithiii opened this issue Jan 25, 2023 · 2 comments · Fixed by #534

Comments

@viswajithiii
Copy link
Contributor

viswajithiii commented Jan 25, 2023

Description

If I try to mock an interface with some returned values named (and others left as _), mockery generates invalid code, as it copies the _ names verbatim when generating the return function.

Mockery Version

2.16.0

Golang Version

1.19.1

Installation Method

  • Binary Distribution
  • Docker
  • brew
  • go install
  • Other: [specify]

Steps to Reproduce

  1. Have an interface like
//go:generate mockery -name=MyToyInterface --with-expecter
type MyToyInterface {
  MyMethod() (_ int, err error)
}
  1. Run go generate

Expected Behavior

Valid generated code, like:

func (_c *MyToyInterface_MyMethod_Call) Return(_a0 int, err error) *MyToyInterface_MyMethod_Call {
	_c.Call.Return(_a0, err)
	return _c
}

Actual Behavior

You will see that the generated code is invalid, like:

func (_c *MyToyInterface_MyMethod_Call) Return(_ int, err error) *MyToyInterface_MyMethod_Call {
	_c.Call.Return(_, err)
	return _c
}

This is because it tries to use the _ as a value, which is a compile-time error: cannot use _ as value or type

@viswajithiii viswajithiii changed the title Cannot use mocks when only some return parameters are named Generated code is invalid when only some return parameters are named Jan 25, 2023
@viswajithiii
Copy link
Contributor Author

If you agree that this issue is valid, I'm happy to send a PR to fix. 😊

@viswajithiii
Copy link
Contributor Author

Actually, this is 100% a bug, and the fix was tiny; went ahead and sent a PR here: #534.

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

Successfully merging a pull request may close this issue.

1 participant