indirect drills into interfaces and pointers, returning the pointed-at value. If it encounters a nil interface or pointer, indirect returns that nil value. This can turn into an infinite loop given a cyclic chain, but it matches the Go 1 behavior.
(vf reflect.Value)
| 814 | // This can turn into an infinite loop given a cyclic chain, |
| 815 | // but it matches the Go 1 behavior. |
| 816 | func indirect(vf reflect.Value) reflect.Value { |
| 817 | for vf.Kind() == reflect.Interface || vf.Kind() == reflect.Pointer { |
| 818 | if vf.IsNil() { |
| 819 | return vf |
| 820 | } |
| 821 | vf = vf.Elem() |
| 822 | } |
| 823 | return vf |
| 824 | } |
| 825 | |
| 826 | func (p *printer) marshalStruct(tinfo *typeInfo, val reflect.Value) error { |
| 827 | s := parentStack{p: p} |