moq icon indicating copy to clipboard operation
moq copied to clipboard

Support non-basic type constraints

Open samherrmann opened this issue 1 year ago • 1 comments

This issue is to track the limitation that was mentioned in the description of #175.

Consider the following interface:

type Sorter[T comparable] interface {
	Sort(slice []T) []T
}

When generating a mock using moq v0.3.2, the following implementation check is created:

var _ Sorter[comparable] = &SorterMock[comparable]{}

This code is not valid due to the following reason:

cannot use type comparable outside a type constraint: interface is (or embeds) comparable

samherrmann avatar Aug 07 '23 20:08 samherrmann

My current workaround is to use the -skip-ensure flag. This workaround prevents me from having to manually modify the generated mock file, which is crucial because this allows go generate ./... to be re-run on the project without overwriting manual changes.

samherrmann avatar Aug 11 '23 18:08 samherrmann