math/big: DeepEqual return false when comparing Rat with SetString("0") and SetInt64(0) #50944
Labels
FrozenDueToAge
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
After CL 24430, reflect.DeepEqual no longer returns true when comparing a *Rat built with (*Rat).SetString("0") with one built with (*Rat).SetInt64(0).
These should be equivalent, but because (*Rat).SetString does not call norm() when returning the zero value, the result of reflect.DeepEqual will be false.
One could suggest that developers should use (*Rat).Cmp instead of relying on reflect.DeepEqual, but if a (*Rat) is part of a
larger struct that is being compared, this can be cumbersome.
Given the following test scenario,
The expected result should be S = T, but due to SetString return without calling norm, the result of DeepEqual(S, T) is always false.
A code snippet to simulate this scenario,
Playground: https://go.dev/play/p/RyS70bghhue
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: