Open laushunyu opened 1 year ago
it seem like that the assignee to a interface does not save it's impletation's value. so when converting to another interface, it not work?
in yaegi/interp/run.go:410 v = v.Elem()
it seem like that the assignee to a interface does not save it's impletation's value. so when converting to another interface, it not work?
in yaegi/interp/run.go:410 v = v.Elem()
the address of empty struct value is 0, so we cannot get the implementation. another field IType to store Type is nesserary. or the type of IValue should be reflect.Value
another case:
package main
import "fmt"
type A struct {
Fuck string
Shit int
}
func (a A) String() string {
return "String"
}
func (a A) GoString() string {
return "GoString"
}
type Stringer interface {
String() string
}
func GetGoString() (fmt.GoStringer, bool) {
var a Stringer = &A{}
goStr, ok := a.(fmt.GoStringer)
return goStr, ok
}
if define the interface in src package, it can compare every method (in interp/run.go:379
) then return true; but interface in bin package(fmt.Stringer) is not work.
and
switch a.(type) {
case fmt.GoStringer:
}
is not working too, even if interface is in the same src package, i found that yaegi/interp/run.go:2997:
// match against 1 type: assign var to concrete value
dest value can also be a interface too, so we should compare all its method.
The commit 25f44d6 seem like had a wrong issue referenced.
The following program
sample.go
triggers an unexpected resultExpected result
Got
Yaegi Version
v0.15.1
Additional Notes
hi, assertion from a interface to another interface is not working.
I haven't found the exact location in the source code where this bug occurs yet, but I can suggest some possible causes and solutions for the bug:
output:
I think when trying to know whether
v.CanConvert()
, we shouldElem
the v ifv.Kind == reflect.Interface
.