uber-go / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
1.82k stars 104 forks source link

proposal: ignore interfaces that contains type constraints #93

Closed hoonmin closed 9 months ago

hoonmin commented 9 months ago

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 commented 9 months ago

CLA assistant check
All committers have signed the CLA.

hoonmin commented 9 months ago

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!