The empty interface (interface{}), and its variants (such as []interface{} and map[string]interface{}), are commonly used in Go to (json) Unmarshal arbitrary data. Within Yaegi, all interface types are wrapped in a valueInterface struct in order to retain all the information needed for a consistent internal state (as reflect is not enough to achieve that). However, this wrapping ends up being problematic when it comes to the type assertions related to the aforementioned Unmarshaling.
Therefore, this PR is an attempt to consider the empty interface (and its variants) as an exception within Yaegi, that should never be wrapped within a valueInterface, and to treat it similarly to the other basic Go types. The assumption is that the wrapping should not be needed, as there is no information about implemented methods to maintain.
Fixes #984
Fixes #829
Fixes #1015
30 lines
434 B
Go
30 lines
434 B
Go
package main
|
|
|
|
type Root struct {
|
|
Name string
|
|
}
|
|
|
|
type One struct {
|
|
Root
|
|
}
|
|
|
|
type Hi interface {
|
|
Hello() string
|
|
}
|
|
|
|
type Hey interface {
|
|
Hello() string
|
|
}
|
|
|
|
func (r *Root) Hello() string { return "Hello " + r.Name }
|
|
|
|
func main() {
|
|
// TODO(mpl): restore when type assertions work again.
|
|
// var one interface{} = &One{Root{Name: "test2"}}
|
|
var one Hey = &One{Root{Name: "test2"}}
|
|
println(one.(Hi).Hello())
|
|
}
|
|
|
|
// Output:
|
|
// Hello test2
|