Skip to content

Commit

Permalink
Fix mock generation of function pointer signature parameters (#227)
Browse files Browse the repository at this point in the history
Before this fix an interface method with a parameter such as
`func(goa.Endpoint)` would be generated as
`func(goa.design/goa/v3/pkg.Endpoint)` instead of something that is
actually valid Go.
  • Loading branch information
douglaswth committed May 4, 2023
1 parent 6c3314f commit f4fd9e7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions mock/cmd/cmg/pkg/generate/_tests/extensive/extensive.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type (
C float64
}, func(int) (bool, error))
NamedTypes(Struct, Array, io.Reader, imported.Type, goa.Endpoint, Generic[uint, string, Struct, Array]) (Struct, Array, io.Reader, imported.Type, goa.Endpoint, Generic[uint, string, Struct, Array])
FuncNamedTypes(func(Struct, Array, io.Reader, imported.Type, goa.Endpoint, Generic[uint, string, Struct, Array])) func(Struct, Array, io.Reader, imported.Type, goa.Endpoint, Generic[uint, string, Struct, Array])
VariableConflicts(f, m uint)
}

Expand Down
18 changes: 18 additions & 0 deletions mock/cmd/cmg/pkg/generate/_tests/extensive/mocks/extensive.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion mock/cmd/cmg/pkg/generate/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ func (ta *typeAdder) name(tt types.Type) (name string) {
name = "*" + ta.name(t.Elem())
case *types.Signature:
b := &bytes.Buffer{}
types.WriteSignature(b, t, nil)
types.WriteSignature(b, t, func(p *types.Package) string {
i := addImport(newImport(p.Path(), p.Name()), ta.stdImports, ta.extImports, ta.intImports, ta.modPath)
return i.AliasOrPkgName()
})
name = "func" + b.String()
case *types.Slice:
name = "[]" + ta.name(t.Elem())
Expand Down
2 changes: 1 addition & 1 deletion mock/cmd/cmg/pkg/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const (
// Minor version number
Minor = 17
// Build number
Build = 0
Build = 1
// Suffix - set to empty string in release tag commits.
Suffix = ""
)
Expand Down

0 comments on commit f4fd9e7

Please sign in to comment.