yaegi
yaegi copied to clipboard
The `extract` output should not use `func` as the field type.
The following program sample.go
triggers an unexpected result
package main
import (
"go/types"
)
type B struct {
}
// Alignof returns the alignment of a variable of type T.
// Alignof must implement the alignment guarantees required by the spec.
func (b *B) Alignof(T types.Type) int64 {
return 0
}
// Offsetsof returns the offsets of the given struct fields, in bytes.
// Offsetsof must implement the offset guarantees required by the spec.
func (b *B) Offsetsof(fields []*types.Var) []int64 {
return nil
}
// Sizeof returns the size of a variable of type T.
// Sizeof must implement the size guarantees required by the spec.
func (b *B) Sizeof(T types.Type) int64 {
return 1
}
var (
originTables = map[types.Sizes]string{}
)
func Register(table types.Sizes, str string) {
originTables[table] = str
}
func main() {
Register(&B{}, "ss")
}
Expected result
no panic.
Got
sample.go:34:2: panic
sample.go:38:12: panic
run: runtime error: hash of unhashable type stdlib._go_types_Sizes
Yaegi Version
0.15.0
Additional Notes
// _go_types_Object is an interface wrapper for Object type type _go_types_Object struct { IValue interface{} WExported func() bool WId func() string WName func() string WParent func() *types.Scope WPkg func() *types.Package WPos func() token.Pos WString func() string WType func() types.Type }
The key of a map cannot contain the func
field.
Maybe we can modify the output file like this:
type _go_types_Object struct {
IValue interface{}
}
func (W _go_types_Object) Exported() bool {
return W.IValue.(types.Object).Exported()
}
func (W _go_types_Object) Id() string {
return W.IValue.(types.Object).Id()
}
func (W _go_types_Object) Name() string {
return W.IValue.(types.Object).Name()
}
func (W _go_types_Object) Parent() *types.Scope {
return W.IValue.(types.Object).Parent()
}
func (W _go_types_Object) Pkg() *types.Package {
return W.IValue.(types.Object).Pkg()
}
func (W _go_types_Object) Pos() token.Pos {
return W.IValue.(types.Object).Pos()
}
func (W _go_types_Object) String() string {
return W.IValue.(types.Object).String()
}
func (W _go_types_Object) Type() types.Type {
return W.IValue.(types.Object).Type()
}
@mvertes What do you think?