encoding/gob: permit registering duplicate names #36345
Labels
FeatureRequest
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
In go1.9, type aliases were introduced. The purpose of type aliases is to permit the movement of types from one location to another. This implies:
The use of type aliases interacts poorly with gob-encoded data stored on disk that represent interface values as
gob
was a developed in an era where there was one-to-one relationship between types and names.Consider the following examples.
At some point in the past, we gob-encoded is stored on disk using something like:
On the decoder side, this works fine with code like:
At some point in the future, suppose we move
Rect
, now decoding fails:The problem is that the full type name is encoded in the gob wire data. Trying to decode the data at a later date does not know about the movement of the type due to type aliases.
Given that problem, one would think that you could just use
gob.RegisterName
to manually register the old name:However, that panics with:
I propose the following changes:
gob
be better documented about the interaction of type aliases and serialization of interface values.gob.RegisterName
be relaxed to permit duplicate names. However, this can cause confusion in the implementation as to which name to use when marshaling. Alternatively, we could add agob.RegisterAlias
that makes it clear that the duplicate names are aliases.The text was updated successfully, but these errors were encountered: