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

Interface used as input argument of function called outside of the interpreter #69

Closed
ldez opened this issue Jan 31, 2019 · 1 comment
Closed
Labels
bug Something isn't working
Milestone

Comments

@ldez
Copy link
Contributor

ldez commented Jan 31, 2019

tree
├── _fninterface
│   └── src
│       └── github.com
│           └── foo
│               └── bar
│                   └── bar.go
└ my_test.go
my_test.go
package sample

import (
	"fmt"
	"path/filepath"
	"reflect"
	"testing"

	"github.com/containous/dyngo/interp"
	"github.com/containous/dyngo/stdlib"
)

type Huu struct {
	name string
}

func (h *Huu) Hello() {
	fmt.Println("Hello", h.name)
}

func TestInterfaceIn(t *testing.T) {
	goPath, err := filepath.Abs("./_fninterface/")
	if err != nil {
		t.Fatal(err)
	}

	// Init go interpreter
	i := interp.New(interp.Opt{
		GoPath: goPath,
	})
	i.Use(stdlib.Value, stdlib.Type) // Use binary standard library

	if _, err := i.Eval(`import "github.com/foo/bar"`); err != nil {
		t.Fatal(err)
	}

	// Bar
	fnCall, err := i.Eval(`bar.Call()`)
	if err != nil {
		t.Fatal(err)
	}

	fnCall.Call([]reflect.Value{reflect.ValueOf(&Huu{name: "test"})})
}
bar.go
package bar

import (
	"fmt"
)

type Foo interface {
	Hello()
}

func Call() func(Foo) {
	return func(foo Foo) {
		fmt.Println("in")
		foo.Hello()
	}
}

Got:

   fninterface_test.go:34: _fninterface/src/github.com/foo/bar/bar.go:14:3: undefined selector: Hello
@ldez ldez added the bug Something isn't working label Jan 31, 2019
@ldez ldez added this to the alpha milestone Jan 31, 2019
@mvertes
Copy link
Member

mvertes commented Jun 18, 2019

@ldez, I propose to close this issue, obsolete now

@ldez ldez closed this as completed Jun 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants