-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
encoding/binary: fix NativeEndian == BigEndian || NativeEndian == LittleEndian #67026
Comments
As they are different types, equality isn't possible (nor is it generally expected of unexported types). |
@seankhliao My point is that they should not be different types, but instead defined using a type alias. For this reason I'm asking this issue to be reopened. |
Change https://go.dev/cl/581655 mentions this issue: |
@seankhliao Please review CL581655 which fixes this issue. |
Cc: @randall77 because #57237 (comment) |
I realize that my However for
So this issue deserved to be closed. |
This is a follow-up to #57237.
In comment #57237 (comment) @robpike implied that the value of
binary.NativeEndian
should be comparable with==
to thebinary.BigEndian
andbinary.LittleEndian
values.Unfortunately in the current implementation added in Go 1.21, comparisons with both values fail because the type of
binary.NativeEndian
is different of both values because of the use of an embedded type:Also, it makes no sense to have a specific name (
NativeEndian
) forbinary.NativeEndian.String()
. It should be eitherBigEndian
orLittleEndian
(or any weired concrete endianness added in the future).Proposed fix
Define the type of
binary.NativeEndian
using a type alias instead of type embedding.Go version
go version go1.22.2 darwin/arm64
What did you do?
https://go.dev/play/p/niinanpbVuC
What did you see happen?
What did you expect to see?
The text was updated successfully, but these errors were encountered: