fix: recursive struct function call

This commit is contained in:
Nicholas Wiersma
2020-06-03 00:18:04 +02:00
committed by GitHub
parent 3c88542180
commit 01e4cdea70
5 changed files with 113 additions and 5 deletions

View File

@@ -54,6 +54,25 @@ func genValueRecv(n *node) func(*frame) reflect.Value {
}
}
func genValueRecvInterfacePtr(n *node) func(*frame) reflect.Value {
v := genValue(n.recv.node)
fi := n.recv.index
return func(f *frame) reflect.Value {
r := v(f)
r = r.Elem().Elem()
if len(fi) == 0 {
return r
}
if r.Kind() == reflect.Ptr {
r = r.Elem()
}
return r.FieldByIndex(fi)
}
}
func genValueAsFunctionWrapper(n *node) func(*frame) reflect.Value {
value := genValue(n)
typ := n.typ.TypeOf()
@@ -176,6 +195,18 @@ func genValueInterface(n *node) func(*frame) reflect.Value {
}
}
func genValueDerefInterfacePtr(n *node) func(*frame) reflect.Value {
value := genValue(n)
return func(f *frame) reflect.Value {
v := value(f)
if v.IsZero() {
return v
}
return v.Elem().Elem()
}
}
func zeroInterfaceValue() reflect.Value {
n := &node{kind: basicLit, typ: &itype{cat: nilT, untyped: true}}
v := reflect.New(interf).Elem()