rjeczalik / interfaces

Code generation tools for Go.
MIT License
420 stars 31 forks source link

`interfacer` doesn't preserve variadic arguments #7

Closed jinnovation closed 5 years ago

jinnovation commented 6 years ago

Input struct: "github.com/gocql/gocql".Session

Output:

// Session is an interface generated for "github.com/gocql/gocql".Session.
type Session interface {
// ...
    Query(string, []interface{}) *gocql.Query
// ...
}

Corresponding function signature (see github.com/gocql/gocql/session.go:

func (s *Session) Query(stmt string, values ...interface{}) *Query
rjeczalik commented 6 years ago

Actually the []interface{} is what what go/types package returns, not the interfacer one. I can take a look if there's any field that can be used to make a distinction.

For now workaround - please edit the signature manually 😇

Thanks @jinnovation for the report!

sbward commented 5 years ago

Hey there, this issue is really old, but there is a way to fix this using types.Signature.Variadic() method if you want to do the formatting manually.

rjeczalik commented 5 years ago

@sbward Thanks for pointing out, I must have missed that. Would you like to try sending a PR for that?

sbward commented 5 years ago

In my fork, I attempted to do it while preserving your structer/interfacer shared formatting code, but in the end I decided to just use gotypes Signature String formatter and delete structer. As a result my fork is now just a simpler implementation of interfacer by itself. It's up to you to decide if you want to take a similar approach and break apart interfacer/structer implementations, or bite the bullet and figure out how to use Signature.Variadic in the existing codebase.

rjeczalik commented 5 years ago

@sbward Added support for variadic args, lmk how that works for you.