vburenin / ifacemaker

Generate interfaces from structure methods.
Apache License 2.0
320 stars 43 forks source link

Support variadic parameters #56

Closed erstam closed 7 months ago

erstam commented 2 years ago

I have a Bar struct that implements AddFoo() and GetFoo(). AddFoo() takes a variadic list of Foo instances. Foo is declared in pkg which is imported.

Ifacemaker produces this:


// Generated by ifacemaker, do not edit

package interfaces

import "github.com/user/pkg"

// BarInterface ...
type BarInterface {
    AddFoo(foos ...**Foo**)
    GetFoo() (foo pkg.Foo)
}```

Here you can see that the variadic parameter is unresolved because it is not appended by `pkg.`.

Seen with Go 1.18.3 and ifacemaker v1.2.0,
vburenin commented 1 year ago

Can you give more concrete example with exact input:

Here is mine:

(w)➜  ifacemaker git:(vb-upgrade) ✗ cat tests/variadics.go 
package tests

import "github.com/vburenin/ifacemaker/tests/pkg"

type VariadicTest struct {
    // Name is the name of the test.
}

func (vt *VariadicTest) Name(a string, b ...string) string {
    return "VariadicTest"
}

func (vt *VariadicTest) AddFoo(a ...*pkg.MyFoo) string {
    return "VariadicTest"
}
(w)➜  ifacemaker git:(vb-upgrade) ✗ ./ifacemaker -f tests/variadics.go -s VariadicTest --iface VariadTest --pkg tests
// Code generated by ifacemaker; DO NOT EDIT.

package tests

import (
    "github.com/vburenin/ifacemaker/tests/pkg"
)

// VariadTest ...
type VariadTest interface {
    Name(a string, b ...string) string
    AddFoo(a ...*pkg.MyFoo) string
}
erstam commented 1 year ago

Hello, it has been a long time and now it seems I am not able to reproduce this issue anymore. Using fairly the same example as you I get the same result. So I think you can mark this one as solved. Thanks!

erstam commented 7 months ago

Seems ok, will reopen if bug happens again