interp: add support of interface wrappers to type assertions

Store the interpreter value of the interface object to wrap as
a field called IValue, at offset 0 in wrapper structures.

Update extract to include IValue field.

In typeAssert, detect interface wrapper, and dereference the
interpreter value from IValue wrapper field.

Fixes #1166.
This commit is contained in:
Marc Vertes
2021-07-12 17:10:13 +02:00
committed by GitHub
parent 78d7e85352
commit fc970799a1
183 changed files with 707 additions and 80 deletions

View File

@@ -52,6 +52,7 @@ func init() {
// _fmt_Formatter is an interface wrapper for Formatter type
type _fmt_Formatter struct {
IValue interface{}
WFormat func(f fmt.State, verb rune)
}
@@ -59,6 +60,7 @@ func (W _fmt_Formatter) Format(f fmt.State, verb rune) { W.WFormat(f, verb) }
// _fmt_GoStringer is an interface wrapper for GoStringer type
type _fmt_GoStringer struct {
IValue interface{}
WGoString func() string
}
@@ -66,6 +68,7 @@ func (W _fmt_GoStringer) GoString() string { return W.WGoString() }
// _fmt_ScanState is an interface wrapper for ScanState type
type _fmt_ScanState struct {
IValue interface{}
WRead func(buf []byte) (n int, err error)
WReadRune func() (r rune, size int, err error)
WSkipSpace func()
@@ -85,13 +88,15 @@ func (W _fmt_ScanState) Width() (wid int, ok bool) { return W.WWidth() }
// _fmt_Scanner is an interface wrapper for Scanner type
type _fmt_Scanner struct {
WScan func(state fmt.ScanState, verb rune) error
IValue interface{}
WScan func(state fmt.ScanState, verb rune) error
}
func (W _fmt_Scanner) Scan(state fmt.ScanState, verb rune) error { return W.WScan(state, verb) }
// _fmt_State is an interface wrapper for State type
type _fmt_State struct {
IValue interface{}
WFlag func(c int) bool
WPrecision func() (prec int, ok bool)
WWidth func() (wid int, ok bool)
@@ -105,6 +110,7 @@ func (W _fmt_State) Write(b []byte) (n int, err error) { return W.WWrite(b) }
// _fmt_Stringer is an interface wrapper for Stringer type
type _fmt_Stringer struct {
IValue interface{}
WString func() string
}