Skip to content
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: inconsistency between Write and Read #22772

Closed
opennota opened this issue Nov 17, 2017 · 2 comments
Closed

encoding/binary: inconsistency between Write and Read #22772

opennota opened this issue Nov 17, 2017 · 2 comments
Labels
FrozenDueToAge Proposal v2 A language change or incompatible library change
Milestone

Comments

@opennota
Copy link

What version of Go are you using (go version)?

1.9.2

What did you do?

https://play.golang.org/p/aa0RIwHB_2

What did you expect to see?

If Write can encode the struct, Read can decode it.

What did you see instead?

Read panics:

reflect.Value.SetUint using value obtained using unexported field

Probably #Go2, unless there's a way to make Read decode structs with unexported fields.

@bradfitz bradfitz added the v2 A language change or incompatible library change label Nov 17, 2017
@bradfitz bradfitz added this to the Unplanned milestone Nov 17, 2017
@ianlancetaylor
Copy link
Contributor

In general the reflect package permits you to do exactly the operations that the language permits you to do. However, the reflect package is given special dispensation to read unexported fields, even though they can not be read in the language, because otherwise it would be impossible to implement the fmt package. That is what you are observing. If we think that consistency of Read and Write in the encoding/binary package is important, then the fix is going to be to change Write to reject unexported fields.

@ianlancetaylor
Copy link
Contributor

We aren't going to change anything here. Closing as unfortunate.

@golang golang locked and limited conversation to collaborators Mar 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Proposal v2 A language change or incompatible library change
Projects
None yet
Development

No branches or pull requests

5 participants