Functions in a struct fields are always wrapped (as potentially used by the runtime), so generate a function wrapper also for closure when assigned to a struct field. When such a function is called from the interpreter, ensure that interface arguments are also wrapped so method and receiver resolution can be performed. Fixes partially #1043.
27 lines
327 B
Go
27 lines
327 B
Go
package main
|
|
|
|
type I interface{ Hello() }
|
|
|
|
type T struct{ Name string }
|
|
|
|
func (t *T) Hello() { println("Hello", t.Name) }
|
|
|
|
type FT func(i I)
|
|
|
|
type ST struct{ Handler FT }
|
|
|
|
func newF() FT {
|
|
return func(i I) {
|
|
i.Hello()
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
st := &ST{}
|
|
st.Handler = newF()
|
|
st.Handler(&T{"test"})
|
|
}
|
|
|
|
// Output:
|
|
// Hello test
|