Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Methods containing type literals can't be mocked in source mode #8

Closed
peterstace opened this issue Aug 18, 2015 · 3 comments
Closed

Comments

@peterstace
Copy link
Contributor

If an interface has a method containing a literal struct type, then mockgen isn't able to generate a mock when using source mode.

E.g. interfaces.go:

type Foo interface {
    Baz(struct{})
}

type Bar interface {
    Baz() struct{}
}

$ mockgen -source=interfaces.go gives the following error: 2015/08/18 15:02:43 Loading input failed: interfaces.go:6:5: failed parsing arguments: don't know how to parse type *ast.StructType.

The mocks can be generated successfully when using mockgen in reflect mode.

@dsymonds
Copy link
Contributor

Yeah, it's in general very hard to handle that. We could treat struct{} as a special case, like we do for interface{}.

@dsymonds
Copy link
Contributor

FYI, you should switch to reflect mode. It's way more reliable.

@peterstace
Copy link
Contributor Author

Thanks @dsymonds !

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

No branches or pull requests

2 participants