-
Notifications
You must be signed in to change notification settings - Fork 147
Open
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.
Metadata
Metadata
Assignees
Labels
No labels