Skip to content

Interfaces syntactically incorrect for functions with functions as arguments #32

@OscarVanL

Description

@OscarVanL

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions