From 74282e400c7f52a6e78e09dea7e9f2d1def6fb8b Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Sat, 22 Sep 2012 05:54:11 +1000 Subject: [PATCH] [release-branch.go1] encoding/gob: revert 6348067, which broke compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit ««« backport 3357d8d34ab8 encoding/gob: revert 6348067, which broke compatibility Add commentary to explain better what's going on, but the code change is a simple one-line reversal to the previous form. R=rsc CC=golang-dev https://golang.org/cl/6428072 »»» --- src/pkg/encoding/gob/type.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/pkg/encoding/gob/type.go b/src/pkg/encoding/gob/type.go index 908cc9ce1c..a8ee2fa4a5 100644 --- a/src/pkg/encoding/gob/type.go +++ b/src/pkg/encoding/gob/type.go @@ -749,13 +749,29 @@ func Register(value interface{}) { rt := reflect.TypeOf(value) name := rt.String() - // But for named types (or pointers to them), qualify with import path. + // But for named types (or pointers to them), qualify with import path (but see inner comment). // Dereference one pointer looking for a named type. star := "" if rt.Name() == "" { if pt := rt; pt.Kind() == reflect.Ptr { star = "*" - rt = pt.Elem() + // NOTE: The following line should be rt = pt.Elem() to implement + // what the comment above claims, but fixing it would break compatibility + // with existing gobs. + // + // Given package p imported as "full/p" with these definitions: + // package p + // type T1 struct { ... } + // this table shows the intended and actual strings used by gob to + // name the types: + // + // Type Correct string Actual string + // + // T1 full/p.T1 full/p.T1 + // *T1 *full/p.T1 *p.T1 + // + // The missing full path cannot be fixed without breaking existing gob decoders. + rt = pt } } if rt.Name() != "" { -- 2.50.0