Skip to content

Construct the empty NamedTuple - #113

Open
quinnj-bot[bot] wants to merge 2 commits into
mainfrom
claude/construct-empty-namedtuple
Open

quinnj-bot[bot] wants to merge 2 commits into
mainfrom
claude/construct-empty-namedtuple

Conversation

@quinnj-bot

@quinnj-bot quinnj-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown

Why

construct builds a type with no fields by calling T(), and the empty NamedTuple type has no zero-argument constructor:

StructTypes.construct(Any[], NamedTuple{(), Tuple{}})          # MethodError: no method matching @NamedTuple{}()
StructTypes.constructfrom(NamedTuple{(), Tuple{}}, Dict())      # same
JSON3.read(JSON3.write(NamedTuple()), typeof(NamedTuple()))     # same

What changed

  • Both construct(f, T) and construct(values::Vector{Any}, T) build an empty NamedTuple type with T(()). Other types with no fields still use T().

Scope

  • Only types with no fields change, and only NamedTuple types among them.

Blast Radius

The new branch is taken only for NamedTuple{(), Tuple{}}, which always threw before.

Verification

  • New tests next to the issue Error after v1.7 update #47 tests: the 3 NamedTuple checks throw on main (the Tuple{} check passes on both) and all 4 pass on this branch. Pkg.test() passes on Julia 1.12.6, and JSON3's own test suite passes with this branch.
  • Found by a JSON3 round-trip harness: every empty NamedTuple it wrote failed to read back.

🤖 Generated with Claude Code

quinnj and others added 2 commits November 19, 2026 14:27
These fail on main with a MethodError: construct builds field-less types
with T(), and NamedTuple{(), Tuple{}} has no zero-argument constructor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
construct(f, T) and construct(values, T) returned T() for types with no
fields, which throws for NamedTuple{(), Tuple{}}, so an empty NamedTuple
written by JSON3 could not be read back. They now call T(()) for
NamedTuple types and T() for the rest.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.19%. Comparing base (916621a) to head (4514692).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #113      +/-   ##
==========================================
+ Coverage   78.38%   79.19%   +0.81%     
==========================================
  Files           2        2              
  Lines         421      423       +2     
==========================================
+ Hits          330      335       +5     
+ Misses         91       88       -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.

This branch has not been deployed

No deployments
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.

1 participant