math/big: nil *Int appears to not roundtrip with MarshalText and UnmarshalText #60489
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
https://go.dev/play/p/uV8Vr7trqBv
https://pkg.go.dev/encoding#TextUnmarshaler says:
MarshalText
clearly supports a nil*big.Int
value, marshaling it as<nil>
, butUnmarshalText
rejects it. I think this goes against theTextUnmarshaler
docs.I'm not arguing that marshaling and unmarshaling a nil big int makes any sense, for what it's worth. Just that I always assumed, like the docs say, that roundtripping a value via marshal and then unmarshal was a safe thing to do. If marshaling allows for a nil pointer, unmarshal should support it too - although I'm not sure what it could possibly do, given that it can't set a
*big.Int
receiver to nil. Perhaps set it to its zero value?Note that
MarshalJSON
andUnmarshalJSON
don't have this problem. They both supportnull
, and the unmarshal is simply a no-op. Presumably we could do the same inUnmarshalText
.The text was updated successfully, but these errors were encountered: