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

proposal: ignore interfaces that contains type constraints #93

Merged
merged 4 commits into from
Sep 25, 2023

Conversation

hoonmin
Copy link
Contributor

@hoonmin hoonmin commented Sep 19, 2023

This is a proposal PR to generate mocks without error for following cases:

type Water[R any, C UnsignedInteger] interface {
	Fish(R) []C
}

type UnsignedInteger interface {
	~uint | ~uint32 | ~uint64
}

Go types package seems to wrap interfaces that contain type constraints by checking a type set literal of the form ~T and A|B.
https://github.com/golang/go/blob/master/src/go/types/decl.go#L668

So gomock can just ignore that pattern to generate mocks safely without don't know how to mock method of type errors. I think this can be a better solution for custom type constraints than -exclude flag.

@CLAassistant
Copy link

CLAassistant commented Sep 19, 2023

CLA assistant check
All committers have signed the CLA.

@r-hang r-hang requested a review from JacobOaks September 19, 2023 18:21
Copy link
Contributor

@JacobOaks JacobOaks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is good - just a couple comments. Thanks!

mockgen/generic_go118.go Outdated Show resolved Hide resolved
mockgen/parse.go Outdated Show resolved Hide resolved
hoonmin and others added 2 commits September 24, 2023 23:50
@hoonmin
Copy link
Contributor Author

hoonmin commented Sep 24, 2023

I think this change is good - just a couple comments. Thanks!

I learned some basic but important things from your review. I've applied all of your suggestions, thank you!

Copy link
Contributor

@sywhang sywhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Thanks for making this change!

@sywhang sywhang merged commit 7842e1d into uber-go:main Sep 25, 2023
2 checks passed
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 this pull request may close these issues.

4 participants