traefik / yaegi

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

method and interface with the same name #1454

Closed mvertes closed 2 years ago

mvertes commented 2 years ago

The following program sample.go triggers an unexpected result

package main

type I2 interface {
    I2() string
}

type I interface {
    I2
}

type S struct{}

func (*S) I2() string { return "foo" }

func main() {
    var i I
    _, ok := i.(*S)
    println(ok)
}

Expected result

$ go run ./sample.go
false

Got

$ yaegi ./sample.go
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: /home/marc/yt/issue-1419-2.go:17:11: CFG post-order panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7da514]

goroutine 1 [running]:
github.com/traefik/yaegi/interp.(*Interpreter).cfg.func2.1()
        /home/marc/go/src/github.com/traefik/yaegi/interp/cfg.go:536 +0x78
panic({0xdd04e0, 0x157bad0})
        /home/marc/sdk/go1.19/src/runtime/panic.go:890 +0x262
github.com/traefik/yaegi/interp.isInterfaceSrc(0xc0001868b0?)
        /home/marc/go/src/github.com/traefik/yaegi/interp/type.go:2270 +0x14
github.com/traefik/yaegi/interp.isInterface(0xc000200140?)
        /home/marc/go/src/github.com/traefik/yaegi/interp/type.go:2278 +0x25
github.com/traefik/yaegi/interp.(*itype).equals(0x0, 0xc0002d3200)
        /home/marc/go/src/github.com/traefik/yaegi/interp/type.go:1441 +0x3b
github.com/traefik/yaegi/interp.typecheck.typeAssertionExpr({0xc000187200?}, 0xc00043aa20, 0xc00043b7a0)
        /home/marc/go/src/github.com/traefik/yaegi/interp/typecheck.go:643 +0xb45
github.com/traefik/yaegi/interp.(*Interpreter).cfg.func2(0xc00043a900)
        /home/marc/go/src/github.com/traefik/yaegi/interp/cfg.go:2133 +0x7a3f
github.com/traefik/yaegi/interp.(*node).Walk(0xc00043a900, 0xc000187990, 0xc0001879d8)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:291 +0xad
github.com/traefik/yaegi/interp.(*node).Walk(0xc00043a5a0, 0xc000187990, 0xc0001879d8)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc000439e60, 0xc000187990, 0xc0001879d8)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc0004397a0, 0xc000187990, 0xc0001879d8)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*node).Walk(0xc0002ea7e0, 0xc000187990, 0xc0001879d8)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:288 +0x75
github.com/traefik/yaegi/interp.(*Interpreter).cfg(0xc0002cc000, 0xc0002ea7e0, 0xc0002d42d0, {0xc0002119a0, 0x4}, {0xc0002119a0, 0x4})
        /home/marc/go/src/github.com/traefik/yaegi/interp/cfg.go:62 +0x2b4
github.com/traefik/yaegi/interp.(*Interpreter).CompileAST(0xc0002cc000, {0x1097cc8?, 0xc000218200?})
        /home/marc/go/src/github.com/traefik/yaegi/interp/program.go:92 +0x1ad
github.com/traefik/yaegi/interp.(*Interpreter).compileSrc(0xc0002cc000, {0xc00029e840?, 0x0?}, {0x7ffe69395970?, 0xc00029e840?}, 0xbc?)
        /home/marc/go/src/github.com/traefik/yaegi/interp/program.go:59 +0xb8
github.com/traefik/yaegi/interp.(*Interpreter).eval(0xc0002cc000, {0xc00029e840?, 0xbc?}, {0x7ffe69395970?, 0xc00029e6c0?}, 0xbc?)
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:552 +0x28
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0xc0002cc000, {0x7ffe69395970, 0x1d})
        /home/marc/go/src/github.com/traefik/yaegi/interp/interp.go:510 +0xab
main.runFile(0x7ffe69395970?, {0x7ffe69395970, 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 2

Yaegi Version

v0.14.2

Additional Notes

This bug is related to #1419 once #1452 is applied.