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.
25 lines
290 B
Go
25 lines
290 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
type T []byte
|
|
|
|
func (t *T) Write(p []byte) (n int, err error) { *t = append(*t, p...); return len(p), nil }
|
|
|
|
func foo(w io.Writer) {
|
|
a := w.(*T)
|
|
fmt.Fprint(a, "test")
|
|
fmt.Printf("%s\n", *a)
|
|
}
|
|
|
|
func main() {
|
|
x := T{}
|
|
foo(&x)
|
|
}
|
|
|
|
// Output:
|
|
// test
|