yaegi icon indicating copy to clipboard operation
yaegi copied to clipboard

unexpected `interp.valueInterface` is returned

Open vitrun opened this issue 3 years ago • 2 comments

The following program invoke.go gets an interp.valueInterface, which should be a reflect.Value instead, according to #989

package main

import (
	"context"
	"fmt"
	"github.com/traefik/yaegi/interp"
	"github.com/traefik/yaegi/stdlib"
	"go/build"
)

type DTO = map[string]interface{}

func main() {
	i := interp.New(interp.Options{GoPath: build.Default.GOPATH})
	i.Use(stdlib.Symbols)
	_, _ = i.EvalPath("demo/demo.go")
	v, _ := i.Eval("demo.Invoke")

	req := DTO{
		"trace_id":     "1",
	}
	invoke := v.Interface().(func(ctx context.Context, req DTO) (*DTO, error))
        r, e := invoke(context.Background(), req)
        fmt.Printf("%T, %v", (*r)["trace_id"], e)
}

Expected result:

$ go run ./invoke.go
// interface{}

demo.go

package demo

import "context"

type DTO = map[string]interface{}

func Invoke(ctx context.Context, req DTO) (*DTO, error) {
	return &DTO{
		"trace_id": req["trace_id"],
	}, nil
}

Got:

$ go run ./invoke.go
// interp.valueInterface

yaegi version: 0.9.8

vitrun avatar Dec 17 '20 03:12 vitrun

hi @mpl, do we have a plan to fix the bug? It is very much appreciated if it can be fixed ASAP. I'd like to have a try under your help in case you are busy with work.

vitrun avatar Dec 21 '20 13:12 vitrun

@vitrun it is somewhat high on my TODO list but we are on more critical bugs atm, so neither @mvertes nor I haven't started working on it yet. So of course feel free to have a go at it and sent a PR if you want.

mpl avatar Dec 22 '20 11:12 mpl