traefik / yaegi

Yaegi is Another Elegant Go Interpreter

Home Page:https://pkg.go.dev/github.com/traefik/yaegi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

assign map of interpreted defined interface

mvertes opened this issue · comments

The following program sample.go triggers an unexpected result

package main

import "fmt"

type I interface {
    Name() string
}

type S struct {
    iMap map[string]I
}

func main() {
    s := S{}
    s.iMap = map[string]I{}
    fmt.Println(s)
}

Expected result

$ go run ./sample.go
{map[]}

Got

$ yaegi ./sample.go
./sample.go:14:7: panic
run: reflect.Set: value of type map[string]interp.valueInterface is not assignable to type map[string]interface {}
goroutine 1 [running]:
runtime/debug.Stack()
        /home/marc/sdk/go1.19/src/runtime/debug/stack.go:24 +0x65
github.com/traefik/yaegi/interp.(*Interpreter).Execute.func1()
        /home/marc/go/src/github.com/traefik/yaegi/interp/program.go:141 +0x94
panic({0xd83ce0, 0xc000114af0})
        /home/marc/sdk/go1.19/src/runtime/panic.go:884 +0x212
github.com/traefik/yaegi/interp.runCfg.func1()
        /home/marc/go/src/github.com/traefik/yaegi/interp/run.go:193 +0x148
panic({0xd83ce0, 0xc000114af0})
        /home/marc/sdk/go1.19/src/runtime/panic.go:884 +0x212
reflect.Value.assignTo({0xc00010e5a0?, 0xc000116298?, 0x0?}, {0xeb701c, 0xb}, 0xdc6c80, 0x0)
        /home/marc/sdk/go1.19/src/reflect/value.go:3145 +0x2a5
reflect.Value.Set({0xdc6c80?, 0xc0001162a8?, 0x6?}, {0xc00010e5a0?, 0xc000116298?, 0xc000187938?})
        /home/marc/sdk/go1.19/src/reflect/value.go:2160 +0xeb
github.com/traefik/yaegi/interp.assign.func4(0xc0002d4210?)
        /home/marc/go/src/github.com/traefik/yaegi/interp/run.go:701 +0x19f
github.com/traefik/yaegi/interp.runCfg(0xc00043cea0, 0xc0002d4210, 0xc00043c480?, 0x0?)
        /home/marc/go/src/github.com/traefik/yaegi/interp/run.go:201 +0x29d
github.com/traefik/yaegi/interp.(*Interpreter).run(0xc0002d2000, 0xc00043c480, 0xc0002d4000?)
        /home/marc/go/src/github.com/traefik/yaegi/interp/run.go:120 +0x38e
github.com/traefik/yaegi/interp.(*Interpreter).Execute(0xc0002d2000, 0xc00038f950)
        /home/marc/go/src/github.com/traefik/yaegi/interp/program.go:167 +0x24b
github.com/traefik/yaegi/interp.(*Interpreter).eval(0xc0002d2000, {0xc000294630?, 0xaa?}, {0x7ffea0ff2963?, 0xc0002944d0?}, 0xaa?)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:621 +0x5c
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0xc0002d2000, {0x7ffea0ff2963, 0x1d})
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:514 +0xab
main.runFile(0x7ffea0ff2963?, {0x7ffea0ff2963, 0x1d}, 0x0)
        /home/marc/go/src/github.com/traefik/yaegi/cmd/yaegi/run.go:153 +0xee
main.run({0xc000036050?, 0x1, 0x1})
        /home/marc/go/src/github.com/traefik/yaegi/cmd/yaegi/run.go:116 +0xbec
main.main()
        /home/marc/go/src/github.com/traefik/yaegi/cmd/yaegi/yaegi.go:144 +0x2cb

exit status 1

Yaegi Version

v0.14.1

Additional Notes

This bug is related to #1426, once #1445 has been merged.