Skip to content

Adopt #58: flatten the map element loop - #78

Merged
creasty merged 4 commits into
masterfrom
feat/addressable-structs
Sep 12, 2026
Merged

Adopt #58: flatten the map element loop#78
creasty merged 4 commits into
masterfrom
feat/addressable-structs

Conversation

@creasty

@creasty creasty commented Sep 12, 2026

Copy link
Copy Markdown
Owner

Adapts #58 (@gitsang) onto the new test suite. Their commit is merged rather than
cherry-picked, so the authorship lands in history.

This changes no behavior, which is not what #58 claims. Its premise does not
reproduce: the snippet in the PR body already prints
{"Maps":{"hello":{"Name":"hello"}}} on abebf4b, the commit it branched from,
and the test it ships passes there unmodified. Every test in the current suite also
passes unchanged after the port — that is the evidence nothing observable moved.

What is left is still worth taking:

  • The element loop switched on the element kind twice, once behind a pointer
    and once not, spelling out struct/slice/map in both. It now switches once:
    dereference first, then copy only when the value is not addressable — which a
    dereferenced pointer already is. The copy and the write-back now happen exactly
    where they are needed, rather than in a duplicated arm.
  • A nil pointer element becomes explicit. It used to be skipped because Elem()
    of a nil pointer has kind Invalid and so matched no case: the right outcome,
    reached by accident. The outcome is unchanged and now pinned, both for the
    caller's nil and for a tag whose JSON says null.

Dropped from #58: the README restructure (it reinstates the CircleCI badge, and
the usage block is kept byte-identical to example/main.go) and
example/output.json (the example fills a field from math/rand, so a checked-in
output is stale the moment it is written).

Verified: make lint, make test, make cover at 100%, and the suite on the
declared floor (GOTOOLCHAIN=go1.21.13).

🤖 Generated with Claude Code

https://claude.ai/code/session_01JjAoN3BBvc6dfT9pog3kMB


Generated by Claude Code

gitsang and others added 3 commits July 3, 2025 16:51
Brings gitsang's commit in as their own, so the authorship lands in history.

Their defaults_test.go hunk is dropped -- that file no longer exists -- and the
equivalent pin follows in the next commit. The README restructure and
example/output.json are dropped too: the README's usage block is kept
byte-identical to example/main.go, and a checked-in output would be stale the
moment it was written, since the example's SetDefaults fills a field from
math/rand.

What this changes is less than #58 reports. Its premise does not reproduce: the
snippet in the PR body already prints {"Maps":{"hello":{"Name":"hello"}}} on
abebf4b, the commit it branched from, and its own test passes there unmodified.
Every test in the suite passes unchanged after the port, which is the evidence
that nothing observable moved.

What is left is still worth having. The old loop switched on the element kind
twice, once behind a pointer and once not, spelling out struct/slice/map in both.
This switches once: dereference first, then copy only when the value is not
addressable -- which a dereferenced pointer already is, so the copy and the
write-back now happen exactly where they are needed. The nil element becomes
explicit as well. It used to be skipped because Elem() of a nil pointer has kind
Invalid and so matched no case, which is the right outcome reached by accident.
The outcome is unchanged, and the next commit pins it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JjAoN3BBvc6dfT9pog3kMB
The flattened loop makes the nil element explicit, so the coverage gate asks for
it, and the case is worth a pin of its own regardless: the key stays and nothing
is allocated behind it. That is not obvious sitting next to a nil pointer field,
where a tag does allocate -- a map element is written through rather than copied
back, so allocating one would have to be a deliberate choice, and it is not made.

Both spellings are covered, the caller's nil and a tag whose JSON says null.
Neither is a behavior change: master already left both alone.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JjAoN3BBvc6dfT9pog3kMB
@codecov

codecov Bot commented Sep 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (272ac74) to head (4009b7a).

Additional details and impacted files
@@            Coverage Diff            @@
##            master       #78   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines          188       191    +3     
=========================================
+ Hits           188       191    +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

#76 landed while this branch was open, and it groups setField's per-field context
into a fieldTag. The flattened element loop keeps its shape; only the recursion
call changes, from setField(v, "", false) to setField(v, fieldTag{fieldName:
tag.fieldName}), so an error raised inside a map element still names the field it
came from.

Nothing else moved: the loop's structure, the nil guard and the write-back are as
merged, and the suite passes with the gate at 100%.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JjAoN3BBvc6dfT9pog3kMB
@creasty
creasty merged commit ae0c078 into master Sep 12, 2026
6 checks passed
@creasty
creasty deleted the feat/addressable-structs branch September 12, 2026 09:18
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.

3 participants