-
Notifications
You must be signed in to change notification settings - Fork 18k
reflect.DeepEqual does not function correctly for Int values. #56991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is working as intended since the types are different. It's no different than this logic: fmt.Println(any(int64(-128)) == any(-128)) // reports false |
Before So either the change in behavior was intentional and the docs were not updated, or the functionality was broken. Either way, this issue should be reviewed. |
@mediaexchange-io
|
@mediaexchange-io Quote from the doc:
In At least go1.4 also reports false. |
@cuonglm This is really odd. I had some code from the 1.12 timeframe that I'm in the process of updating to 1.19. It depended on DeepEqual and passed all of its tests. After I bumped the Go version, tests began to fail. At this point I can't explain why it worked previously, but it did. I'll close this issue since the current behavior is reproducible as far back as 1.4. |
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?
https://go.dev/play/p/tVGd49zEvBc
What did you expect to see?
Output of both lines should be
true
What did you see instead?
reflect.DeepEqual
returned false.Details
According to the documentation for DeepEqual:
Apparently when comparing an ints of different widths, promotion isn't used by DeepEqual. Funny enough, this used to work. I think when the function was changed to
func DeepEqual(x, y any) bool
fromfunc DeepEqual(x, y interface{}) bool
this broke.The text was updated successfully, but these errors were encountered: