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

assign map of interpreted defined interface #1447

Closed
mvertes opened this issue Aug 25, 2022 · 0 comments · Fixed by #1448
Closed

assign map of interpreted defined interface #1447

mvertes opened this issue Aug 25, 2022 · 0 comments · Fixed by #1448
Labels
area/core bug Something isn't working
Milestone

Comments

@mvertes
Copy link
Member

mvertes commented Aug 25, 2022

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.

@mvertes mvertes added bug Something isn't working area/core labels Aug 25, 2022
mvertes added a commit to mvertes/yaegi that referenced this issue Aug 29, 2022
The representation of non empty interfaces defined in the interpreter
is now identical between refType() and frameType() functions, which are
used to generate interpreter objects.

Fixes traefik#1447 and traefik#1426.
mvertes added a commit to mvertes/yaegi that referenced this issue Aug 29, 2022
The representation of non empty interfaces defined in the interpreter
is now identical between refType() and frameType() functions, which are
used to generate interpreter objects.

Fixes traefik#1447 and traefik#1426.
@traefiker traefiker added this to the v0.14.x milestone Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants