Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interfaces syntactically incorrect for functions with functions as arguments #32

Open
OscarVanL opened this issue Dec 29, 2021 · 1 comment

Comments

@OscarVanL
Copy link

OscarVanL commented Dec 29, 2021

I have my own PubSub package, which has a method SubscribeWithCallback. One of the arguments to this function is a function (used as a callback in this case)...

func (ps PubSub) SubscribeWithCallback(
	c context.Context,
	sub pubsub.Subscription,
	callback func(context.Context, pubsub.Message),
) (context.Context, error) {

When I use go:generate with interfacer on my PubSub struct, the resultant interface is not syntactically correct and will not compile...

//go:generate interfacer -for github.com/my/repo/pubsub.PubSub -as psiface.PubSub -o psiface/pubsub_iface.go

pubsub_iface.go looks like this:

// Code generated by interfacer; DO NOT EDIT

package psiface

import (
	"context"
	"github.com/my/repo/psiface"
)

// PubSub is an interface generated for "github.com/my/repo/pubsub.PubSub".
type PubSub interface {
    ....
	SubscribeWithCallback(context.Context, pubsub.Subscription, func(context.Context, cloud.google.com/go/internal/pubsub.Message)) (context.Context, error)
}

This has a syntax error as cloud.google.com/go/internal/pubsub.Message is not a valid type.

It seems that some step must be missing or bugged to handle arguments of functions passed as arguments.

@rjeczalik rjeczalik added the bug label Dec 29, 2021
@rjeczalik
Copy link
Owner

The code responsible for reading package names in typed defs should be improved.

Related #37

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

No branches or pull requests

2 participants