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

Moq ignores package names of arguments of generic types #177

Closed
lindebergue opened this issue Jul 4, 2022 · 4 comments · Fixed by #199
Closed

Moq ignores package names of arguments of generic types #177

lindebergue opened this issue Jul 4, 2022 · 4 comments · Fixed by #199

Comments

@lindebergue
Copy link

When mocking a method with a generic type, moq ignores package names of type arguments.

This works:

package example

//go:generate moq -skip-ensure -stub -rm -out mocks.go . Foo:FooMock

type Bar[T any] struct{}

type Foo interface {
	Foo(bar Bar[Type])
}

But this does not:

package example

//go:generate moq -skip-ensure -stub -rm -out mocks.go . Foo:FooMock

import "path/to/pkg"

type Bar[T any] struct{}

type Foo interface {
	Foo(bar Bar[pkg.Type])
}

The generated code instantiates Bar as Bar[Type] instead of Bar[pkg.Type], failing to compile:

// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq

package example

import (
	"sync"
)

type FooMock struct {
	// FooFunc mocks the Foo method.
	FooFunc func(bar Bar[Type])

	// calls tracks calls to the methods.
	calls struct {
		// Foo holds details about calls to the Foo method.
		Foo []struct {
			// Bar is the bar argument value.
			Bar Bar[Type]
		}
	}
	lockFoo sync.RWMutex
}

I've tried workarounds like dot imports and type aliases, but got the same results. If Bar type is a built-in like map, it works fine.
moq version v0.2.7.

@matryer
Copy link
Owner

matryer commented Oct 1, 2022

Hmm, yeah I guess it's not 'generics ready'. I wonder if you fancy submitting a failing test in a PR?

@ben-haverly-cfa
Copy link

Hey, I actually ran into the same issue. Was just curious if there was any movement on this?

@xsteadfastx
Copy link

i read the changelog of 0.3.0 that said it got generics support. tested it today. still running into this problem.

@xsteadfastx
Copy link

i created a failing test through #177

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.

4 participants