Yaegi does not check embedded type methods when casting to interface
karelorigin opened this issue · comments
Karel commented
The following program sample.go
triggers an unexpected result
package main
import "fmt"
type Interface interface {
Say()
}
type sayer struct {
Interface
}
func (s sayer) Say() {
fmt.Println("Hello there!")
}
type derived struct {
sayer
}
func Cast(v interface{}) (Interface, error) {
i, ok := v.(Interface)
if !ok {
return nil, fmt.Errorf("type %T does not implement Interface", v)
}
return i, nil
}
func run() error {
i, err := Cast(derived{})
if err != nil {
return err
}
i.Say()
return nil
}
func main() {
if err := run(); err != nil {
fmt.Println("A fatal error occured:", err)
}
}
Expected result
$ go run cast-issue.go
// Hello there!
Got
$ yaegi ./cast-issue.go
// A fatal error occured: type struct { Xsayer struct { Interface interp.valueInterface } } does not implement Interface
Yaegi Version
Additional Notes
No response