fix: improve generation of interface wrapper

This commit is contained in:
Marc Vertes
2020-05-03 18:32:04 +02:00
committed by GitHub
parent ff36ec58b1
commit 7fba3fe580
7 changed files with 32 additions and 3 deletions

15
_test/bin5.go Normal file
View File

@@ -0,0 +1,15 @@
package main
import (
"fmt"
"net"
)
func main() {
addr := net.TCPAddr{IP: net.IPv4(1, 1, 1, 1), Port: 80}
var s fmt.Stringer = &addr
fmt.Println(s.String())
}
// Output:
// 1.1.1.1:80

View File

@@ -9,5 +9,5 @@ func main() {
println(b, i)
}
// Output
// Output:
// true 2

View File

@@ -8,3 +8,6 @@ func main() {
a := f()
println(*(a.(*int)))
}
// Output:
// 0

View File

@@ -15,3 +15,6 @@ func main() {
_, err := c.Get("url")
println(strings.Contains(err.Error(), "unsupported protocol scheme"))
}
// Output:
// true

View File

@@ -14,4 +14,5 @@ func main() {
println(t.b)
}
// Output: true
// Output:
// true

View File

@@ -13,3 +13,6 @@ type T struct {
func main() {
println(foo().Name)
}
// Output:
// foo

View File

@@ -594,9 +594,13 @@ func genInterfaceWrapper(n *node, typ reflect.Type) func(*frame) reflect.Value {
w := reflect.New(wrap).Elem()
for i, m := range methods {
if m == nil {
if r := v.MethodByName(names[i]); r.IsValid() {
w.Field(i).Set(r)
continue
}
o := vv.FieldByIndex(indexes[i])
if r := o.MethodByName(names[i]); r.IsValid() {
w.Field(i).Set(o.MethodByName(names[i]))
w.Field(i).Set(r)
} else {
log.Println(n.cfgErrorf("genInterfaceWrapper error, no method %s", names[i]))
}