fix: improve generation of interface wrapper
This commit is contained in:
15
_test/bin5.go
Normal file
15
_test/bin5.go
Normal 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
|
||||
@@ -9,5 +9,5 @@ func main() {
|
||||
println(b, i)
|
||||
}
|
||||
|
||||
// Output
|
||||
// Output:
|
||||
// true 2
|
||||
|
||||
@@ -8,3 +8,6 @@ func main() {
|
||||
a := f()
|
||||
println(*(a.(*int)))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// 0
|
||||
|
||||
@@ -15,3 +15,6 @@ func main() {
|
||||
_, err := c.Get("url")
|
||||
println(strings.Contains(err.Error(), "unsupported protocol scheme"))
|
||||
}
|
||||
|
||||
// Output:
|
||||
// true
|
||||
|
||||
@@ -14,4 +14,5 @@ func main() {
|
||||
println(t.b)
|
||||
}
|
||||
|
||||
// Output: true
|
||||
// Output:
|
||||
// true
|
||||
|
||||
@@ -13,3 +13,6 @@ type T struct {
|
||||
func main() {
|
||||
println(foo().Name)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// foo
|
||||
|
||||
@@ -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]))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user