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

Variadic function issues. #766

Closed
1 of 5 tasks
shortsyoungster opened this issue Mar 11, 2024 · 10 comments · Fixed by #774
Closed
1 of 5 tasks

Variadic function issues. #766

shortsyoungster opened this issue Mar 11, 2024 · 10 comments · Fixed by #774

Comments

@shortsyoungster
Copy link

PLEASE READ

DO NOT submit tickets without first using the latest version of Golang, clearing your local golang package cache, and re-building mockery using the latest Golang version and the latest version of mockery. Please provide evidence this has been done in your issue. Failure to provide this evidence will likely result in your issue being closed.

Description

I am getting this error from mockery for my interface that uses variadic functions. I get it even after setting the flag --unroll-variadic=False. ERR Interface conversion: types.Type is *types.Named, not *types.Slice dry-run=false interface=Name qualified-name=FilePath version=v2.42.0. Deleting the interface methods that use the variadic input fixes the issue.

Mockery Version

2.42.0
Golang Version

1.22

NOTE: Please upgrade to the latest golang version before submitting tickets!

Installation Method

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

Steps to Reproduce

  1. [First Step]
  2. [Second Step]
  3. [etc]

Expected Behavior

Mock is generated.

Actual Behavior

Blank mock, and the following error: ERR Interface conversion: types.Type is *types.Named, not *types.Slice dry-run=false interface=Name qualified-name=FilePath version=v2.42.0

@LandonTClipp
Copy link
Contributor

Hello, please provide a reproducer. Without this, I cannot provide any help.

@shortsyoungster
Copy link
Author

shortsyoungster commented Mar 11, 2024

type MyNewInterface interface {
	FetchData(
		ctx context.Context,
		dataType reflect.Type,
		fetchFunc func(xxx ...yyy.ZZ) ([]aa.BB, error),
	) ([]aa.BB, error)
}

This worked on Mockery v2.20.2

@shortsyoungster
Copy link
Author

I would presume that it has to do with this commit d119c66

@shortsyoungster
Copy link
Author

I have tested on v2.40.0, and everything works, this is the version right before d119c66 so I am fairly confident that it is the cause.

@LandonTClipp
Copy link
Contributor

I think the thing to do here is add your example interface as a fixture and have mockery generate it within this project (mainly for testing/backwards compat reasons), then figure out precisely why this fails. Variadic argument have been the bane of my existence in this project, so I'm guessing we'll need yet another special exception for whatever is going wrong here.

@gurudesu
Copy link

I'm experiencing the same issues here - especially with trying to mock the AWS SDK Go V2 interfaces. As an example, see this struct.

Not a bash on this project (thank you for supporting this) but for the time being we've been pushing folks to use gomock instead since they seem to handle variadic arguments well.

@LandonTClipp
Copy link
Contributor

I'll do what I can to fix this, if anyone would be able to submit a PR that would be great, I probably can't get to it for the next few weeks due to being busy at work.

I hope to not drive people away to the main competition for this project, that irks me :)

@LandonTClipp LandonTClipp self-assigned this Apr 20, 2024
LandonTClipp added a commit to LandonTClipp/mockery that referenced this issue Apr 20, 2024
There are two bugs fixed in this commit:

1. As noted in issue vektra#766, mockery failed to generate a mock because it incorrectly considered the return values themselves to be variadic, which is impossible. The fix is to always consider return tuples non-variadic.
2. The `.EXPECT()` struct had an incorrect signature when the argument was a variadic function. The reason was because it triggered off the presence of `"..."` in the type string instead of triggering off the variadic-ness of the outer function. The fix was to simply use the `variadic` flag to determine if the last argument should be variadic.
@LandonTClipp
Copy link
Contributor

LandonTClipp commented Apr 20, 2024

@shortsyoungster @gurudesu I found the issue and submitted a PR to fix it. If the tests pass I will merge and tag the fix.

Sorry for the delay in getting to this. @gurudesu after you told me you were telling people to use gomock I knew I wouldn't be able to sleep until my competition is crushed, so I hope this fixes your issue 😅

This bug actually had nothing to do with the variadic-ness of the function (although I did find a separate bug that I don't think was part of the original complaint here). It was failing on the return value of the function argument. Details in the linked PR.

PS I guess a way to get me to do stuff is to just say gomock does something better. That should never be the case in my opinion!

@gurudesu
Copy link

Thanks @LandonTClipp! Will try this out and recommend folks in my org to just upgrade 👍

@shortsyoungster
Copy link
Author

This worked for me @LandonTClipp. Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants