traefik / yaegi

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

type conversion and assignment bug #1543

Closed hesining closed 1 year ago

hesining commented 1 year ago

The following program sample.go triggers an unexpected result

package main

import (
    "github.com/traefik/yaegi/interp"
    "log"
)

// Generic example.
func main() {
    // Create a new interpreter context
    i := interp.New(interp.Options{})

    // Run some code: define a new function
    _, err := i.Eval("var cc interface{}")
    if err != nil {
        log.Fatal(err)
    }

    // Access the interpreted f function with Eval
    _, err = i.Eval("cc = 1")
    if err != nil {
        log.Fatal(err)
    }

    _, err = i.Eval("dd := cc.(int)")
    if err != nil {
        log.Fatal(err)
    }
}

Expected result

nothing

Got

1:34: type definition not implemented: typeAssertExpr

Yaegi Version

v0.15.1

Additional Notes

Is the problem caused by type conversion and assignment at the same time ?

mvertes commented 1 year ago

Th same program in a script sample.go works ok:

package main

func main() {
    var cc interface{}
    cc = 1
    dd := cc.(int)
    println(dd)
}
$ yaegi ./sample.go
1

The difference is that Eval() is called multiple times in your case instead of one.