diff options
Diffstat (limited to 'src/pkg/encoding/xml/marshal.go')
| -rw-r--r-- | src/pkg/encoding/xml/marshal.go | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/pkg/encoding/xml/marshal.go b/src/pkg/encoding/xml/marshal.go index e723a193cf..d9522e0b39 100644 --- a/src/pkg/encoding/xml/marshal.go +++ b/src/pkg/encoding/xml/marshal.go @@ -354,18 +354,19 @@ func (p *printer) marshalValue(val reflect.Value, finfo *fieldInfo, startTemplat return nil } - kind := val.Kind() - typ := val.Type() - - // Drill into pointers/interfaces - if kind == reflect.Ptr || kind == reflect.Interface { + // Drill into interfaces and pointers. + // This can turn into an infinite loop given a cyclic chain, + // but it matches the Go 1 behavior. + for val.Kind() == reflect.Interface || val.Kind() == reflect.Ptr { if val.IsNil() { return nil } val = val.Elem() - typ = val.Type() } + kind := val.Kind() + typ := val.Type() + // Check for marshaler. if val.CanInterface() && typ.Implements(marshalerType) { return p.marshalInterface(val.Interface().(Marshaler), defaultStart(typ, finfo, startTemplate)) |
