Repository navigation
Apply StructTypes.defaults to missing fields after field 32 - #111
Open
quinnj-bot[bot] wants to merge 2 commits into
Open
quinnj-bot[bot] wants to merge 2 commits into
quinnj-bot[bot] wants to merge 2 commits into
Conversation
StructTypes.construct(values, T) fills a missing field from StructTypes.defaults(T) only for the first 32 fields. A missing field after that gets nothing, so JSON3.read fails on a wide struct. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #111 +/- ##
==========================================
+ Coverage 78.38% 81.56% +3.17%
==========================================
Files 2 2
Lines 421 423 +2
==========================================
+ Hits 330 345 +15
+ Misses 91 78 -13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Why
JSON3.read(json, T)throwsCannot convert an object of type NothingwhenThas more than 32 fields and the JSON leaves out a field after the 32nd, even whenStructTypes.defaults(T)gives that field a default. The same JSON works when the missing field is one of the first 32. The answer to #104 (fill an excluded field fromStructTypes.defaults) fails on wide structs for this reason.Refs #104.
What changed
StructTypes.construct(values::Vector{Any}, T)fills a missing field fromStructTypes.defaults(T)for every field. Before, fields 33 and up gotnothing.Scope
construct(values, T)path that JSON3 uses to readStructtypes.constructfrom(T, obj)from a struct orNamedTuplesource still ignoresdefaults(T)for a missing field. That path never readdefaults, and changing it is a behavior change rather than this fix.Blast Radius
JSON3 is the caller. A missing field past field 32 that has no default still gets
nothing, as before.Verification
construct(values, T) applies defaults to every missing fielderrors before the fix with theconvertMethodErrorand passes after.julia:1.6).🤖 Generated with Claude Code