archive mode does not support type aliases
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 3.4k
- Forks
- 177
- PR merge metrics
- No merged PRs in 30d
Description
Actual behavior
type MyThing = string
hits can't yet turn ... into a model.Type
Expected behavior
It should mock the interface
To Reproduce
type MyThing = string, then add it to an interface that's mocked in archive mode (think Bazel)
Additional Information
HEAD of everything.
Handling this is implemented in package_mode.go, but not in archive.go. The code at https://github.com/uber-go/mock/blob/main/mockgen/model/model_gotypes.go#L77 handles types.Named but not types.Alias. Should it do both?
diff --git a/mockgen/model/model_gotypes.go b/mockgen/model/model_gotypes.go
index 4596c3d..2703c9b 100644
--- a/mockgen/model/model_gotypes.go
+++ b/mockgen/model/model_gotypes.go
@@ -85,6 +85,17 @@ func typeFromGoTypesType(t types.Type) (Type, error) {
}, nil
}
+ if t, ok := t.(*types.Alias); ok {
+ tn := t.Obj()
+ if tn.Pkg() == nil {
+ return PredeclaredType(tn.Name()), nil
+ }
+ return &NamedType{
+ Package: tn.Pkg().Path(),
+ Type: tn.Name(),
+ }, nil
+ }
+
// only unnamed or predeclared types after here
// Lots of types have element types. Let's do the parsing and error checking for all of them.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with mockgen/model/model_gotypes.go, especially typeFromGoTypesType, and compare the existing handling there with archive.go and package_mode.go. Reproduce the type alias in an interface mocked in archive mode, then verify that archive mode accepts it and generates the mock instead of reporting that it cannot convert the type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100