traefik / yaegi

Yaegi is Another Elegant Go Interpreter
https://pkg.go.dev/github.com/traefik/yaegi
Apache License 2.0
7.02k stars 348 forks source link

Assignment statement compile panic #1606

Closed chikaku closed 2 months ago

chikaku commented 8 months ago

The following program sample.go triggers an unexpected result

package main

import "github.com/traefik/yaegi/interp"

const code = `
package main

func main() {
    a, b, c := 1, 2
    _, _, _ = a, b, c
}
`

func main() {
    i := interp.New(interp.Options{})
    _, err := i.Compile(code)
    println("err:", err.Error())
}

Expected result

err: cannot assign 2 values to 3 variables

Got

panic: runtime error: index out of range [5] with length 5 [recovered]
        panic: 5:2: CFG post-order panic: runtime error: index out of range [5] with length 5

goroutine 1 [running]:
github.com/traefik/yaegi/interp.(*Interpreter).cfg.func2.1()
        /gopath/pkg/mod/github.com/traefik/yaegi@v0.15.1/interp/cfg.go:601 +0x74
panic({0x12b0620?, 0xc0000a8090?})
        /usr/local/go/src/runtime/panic.go:920 +0x270
github.com/traefik/yaegi/interp.(*Interpreter).cfg.func2(0xc0000eb040)
        /gopath/pkg/mod/github.com/traefik/yaegi@v0.15.1/interp/cfg.go:642 +0x9bc5
github.com/traefik/yaegi/interp.(*node).Walk(0xc0000eb040, 0xc0000f5cc8, 0xc0000f5d10)

Yaegi Version

v0.15.1

Additional Notes

No response