traefik / yaegi

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

fix: re-import of identical package with `sym.typ.cat == binPkgT` #1551

Open he11olx opened 1 year ago

he11olx commented 1 year ago

test case:

func main() {
    script1 := `package script
import "encoding/json"
var _ = json.Marshal
`
    script2 := `package script
import "encoding/json"
var _ = json.Marshal
`
    inter := interp.New(interp.Options{GoPath: build.Default.GOPATH})
    _ = inter.Use(stdlib.Symbols)

    inter.Eval(script1)
    _, err := inter.Eval(script2)
    fmt.Println(err)
    // 2:8: json/_.go redeclared in this block
}

Related to: https://github.com/traefik/yaegi/pull/1066/files

CLAassistant commented 1 year ago

CLA assistant check
All committers have signed the CLA.

he11olx commented 1 year ago

Looks like not a bug but a feature. But In REPL, executing two import "fmt" will also report errors.

➜  yaegi
> import "fmt"
: 0x14000030120
> import "fmt"
1:21: fmt/_.go redeclared in this block