Skip to content

Conversation

@ikruglov
Copy link

https://tip.golang.org/doc/go1.6

The reflect package has resolved a long-standing incompatibility between
the gc and gccgo toolchains regarding embedded unexported struct types
containing exported fields. Code that walks data structures using
reflection, especially to implement serialization in the spirit of the
encoding/json and encoding/xml packages, may need to be updated.

The problem arises when using reflection to walk through an embedded
unexported struct-typed field into an exported field of that struct. In
this case, reflect had incorrectly reported the embedded field as exported,
by returning an empty Field.PkgPath. Now it correctly reports the field as
unexported but ignores that fact when evaluating access to exported fields
contained within the struct.

Updating: Typically, code that previously walked over structs and used

f.PkgPath != ""
to exclude inaccessible fields should now use

f.PkgPath != "" && !f.Anonymous
For example, see the changes to the implementations of encoding/json and
encoding/xml.

Also see code for more details

https://tip.golang.org/doc/go1.6

The reflect package has resolved a long-standing incompatibility between
the gc and gccgo toolchains regarding embedded unexported struct types
containing exported fields. Code that walks data structures using
reflection, especially to implement serialization in the spirit of the
encoding/json and encoding/xml packages, may need to be updated.

The problem arises when using reflection to walk through an embedded
unexported struct-typed field into an exported field of that struct. In
this case, reflect had incorrectly reported the embedded field as exported,
by returning an empty Field.PkgPath. Now it correctly reports the field as
unexported but ignores that fact when evaluating access to exported fields
contained within the struct.

Updating: Typically, code that previously walked over structs and used

f.PkgPath != ""
to exclude inaccessible fields should now use

f.PkgPath != "" && !f.Anonymous
For example, see the changes to the implementations of encoding/json and
encoding/xml.

Also see code for more details
@ikruglov
Copy link
Author

i just realized that the problem might be deeper than I thought. If you want to keep compatibility with encode/json you would need to changes ffjson's behavior.

@pquerna
Copy link
Owner

pquerna commented Mar 24, 2016

yes, keeping the behavior the same as encoding/json is a goal -- I started playing with respecting f.Anonymous locally but haven't quite figured out what else needs to change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants