Files
moxa/stdlib/go1_17_encoding.go
Marc Vertes e56db3b82e interp: improve interface wrappers when used by reflect
When an interpreter type implementing an interface is
used by the runtime, the runtime can extract its type
and create new values using reflect, and call methods
on it. The problem is that there will be no interpreted
method counterpart in this case, which makes wrapper panic.

Allow the String() method wrapper to always succeed and
return an empty string if no interpreted method is present.

This allows scripts to define custom flag.Value types on
which the runtime internally instantiates values using
reflect (see isZeroValue in Go src/flag/flag.go).

This workaround could be generalized to all wrappers if
necessary. At this moment, it is convenient to keep the
default behavior of expecting instantiated interpreter
methods, in order to catch interpreter bugs related to
interfaces.

Fixes #1276.
2021-10-08 15:56:06 +02:00

68 lines
2.0 KiB
Go

// Code generated by 'yaegi extract encoding'. DO NOT EDIT.
//go:build go1.17
// +build go1.17
package stdlib
import (
"encoding"
"reflect"
)
func init() {
Symbols["encoding/encoding"] = map[string]reflect.Value{
// type definitions
"BinaryMarshaler": reflect.ValueOf((*encoding.BinaryMarshaler)(nil)),
"BinaryUnmarshaler": reflect.ValueOf((*encoding.BinaryUnmarshaler)(nil)),
"TextMarshaler": reflect.ValueOf((*encoding.TextMarshaler)(nil)),
"TextUnmarshaler": reflect.ValueOf((*encoding.TextUnmarshaler)(nil)),
// interface wrapper definitions
"_BinaryMarshaler": reflect.ValueOf((*_encoding_BinaryMarshaler)(nil)),
"_BinaryUnmarshaler": reflect.ValueOf((*_encoding_BinaryUnmarshaler)(nil)),
"_TextMarshaler": reflect.ValueOf((*_encoding_TextMarshaler)(nil)),
"_TextUnmarshaler": reflect.ValueOf((*_encoding_TextUnmarshaler)(nil)),
}
}
// _encoding_BinaryMarshaler is an interface wrapper for BinaryMarshaler type
type _encoding_BinaryMarshaler struct {
IValue interface{}
WMarshalBinary func() (data []byte, err error)
}
func (W _encoding_BinaryMarshaler) MarshalBinary() (data []byte, err error) {
return W.WMarshalBinary()
}
// _encoding_BinaryUnmarshaler is an interface wrapper for BinaryUnmarshaler type
type _encoding_BinaryUnmarshaler struct {
IValue interface{}
WUnmarshalBinary func(data []byte) error
}
func (W _encoding_BinaryUnmarshaler) UnmarshalBinary(data []byte) error {
return W.WUnmarshalBinary(data)
}
// _encoding_TextMarshaler is an interface wrapper for TextMarshaler type
type _encoding_TextMarshaler struct {
IValue interface{}
WMarshalText func() (text []byte, err error)
}
func (W _encoding_TextMarshaler) MarshalText() (text []byte, err error) {
return W.WMarshalText()
}
// _encoding_TextUnmarshaler is an interface wrapper for TextUnmarshaler type
type _encoding_TextUnmarshaler struct {
IValue interface{}
WUnmarshalText func(text []byte) error
}
func (W _encoding_TextUnmarshaler) UnmarshalText(text []byte) error {
return W.WUnmarshalText(text)
}