structaccess: IsFlattenedEmbed — tagged anonymous fields are named fields - #6554
Merged
Conversation
Collaborator
Integration test reportCommit: 1ec7055
Top 7 slowest tests (at least 2 minutes):
|
denik
force-pushed
the
denik/structaccess-isflattenedembed
branch
2 times, most recently
from
September 8, 2026 18:23
94e7313 to
e955512
Compare
…elds
encoding/json only flattens an anonymous field when its json tag gives no name.
An anonymous field with a name (`json:"leaf"`) is a named field: encoding/json
serializes it as a nested object under that name. A tag that sets only an option
(`json:",omitempty"`) leaves the name empty, so that field is still flattened.
Before this change, structwalk, structdiff, and structaccess all used
`sf.Anonymous` as the sole criterion, causing tagged embeds to be flattened when
they should be nested. The three packages now share structaccess.IsFlattenedEmbed
so they cannot drift from each other.
Concretely:
- structwalk visited fields of a tagged embed at the outer path instead of under
the embed's name, so structdiff reported changes at wrong paths
- structaccess resolved a name through a tagged embed, bypassing the nested-object
boundary encoding/json enforces
No resource type in the repo has tagged anonymous embeds today, so this is
preventive. The refschema golden is unchanged.
Co-authored-by: Isaac
denik
force-pushed
the
denik/structaccess-isflattenedembed
branch
from
September 9, 2026 13:58
e955512 to
1ec7055
Compare
denik
marked this pull request as ready for review
September 9, 2026 14:13
pietern
approved these changes
Sep 9, 2026
Collaborator
Integration test reportCommit: c3ff522
1043 interesting tests: 917 MISS, 125 FAIL, 1 SKIP
Top 50 slowest tests (at least 2 minutes):
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
encoding/json only flattens an anonymous field when its json tag gives no name. An anonymous field with a name (
json:"leaf") is a named field: encoding/json serializes it as a nested object under that name, not by promoting its fields into the outer object.Before this change,
structwalk,structdiff, andstructaccessall usedsf.Anonymousas the sole criterion, so tagged embeds were being flattened. The three packages now sharestructaccess.IsFlattenedEmbedso they cannot drift from each other.The rule: anonymous + no json name + struct type = flatten. Tagged, or a non-struct embedded type = named field.
No resource type in the repo has tagged anonymous embeds today, so this is preventive. The
refschemagolden is unchanged.This pull request and its description were written by Isaac.