Fix #787 changes how interfaces are set on a struct (compositeSparce). This change however makes calling the interface panic. This PR reverts part of the change in #787 and adds a test to ensure it does not break again.
36 lines
331 B
Go
36 lines
331 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
type I interface {
|
|
Foo() string
|
|
}
|
|
|
|
type Printer struct {
|
|
i I
|
|
}
|
|
|
|
func New(i I) *Printer {
|
|
return &Printer{
|
|
i: i,
|
|
}
|
|
}
|
|
|
|
func (p *Printer) Print() {
|
|
fmt.Println(p.i.Foo())
|
|
}
|
|
|
|
type T struct{}
|
|
|
|
func (t *T) Foo() string {
|
|
return "test"
|
|
}
|
|
|
|
func main() {
|
|
g := New(&T{})
|
|
g.Print()
|
|
}
|
|
|
|
// Output:
|
|
// test
|