fix array end handling for first variant alternative in parse_into - #1195
Ramya-9353 wants to merge 3 commits into
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C7uBZYRF8M5U3w49QLn4nW
|
GCOVR code coverage report https://1195.json.prtest2.cppalliance.org/gcovr/index.html Build time: 2026-09-25 17:55:29 UTC |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1195 +/- ##
===========================================
- Coverage 93.72% 93.47% -0.25%
===========================================
Files 85 85
Lines 8981 8990 +9
===========================================
- Hits 8417 8403 -14
- Misses 564 587 +23
... and 9 files with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
|
|
The top handler is never inside an array, so nested handlers have no array end to forward to it. The function was only reached through the variant handler's on_array_end misrouting.
|
Pushed a fix for the codecov/project failure. The two lines it lost are |
|
An automated preview of the documentation is available at https://1195.json.prtest2.cppalliance.org/libs/json/doc/html/index.html If more commits are pushed to the pull request, the docs will rebuild at the same URL. 2026-09-25 17:34:02 UTC |
|
|
|
|
||
| // an incomplete array must not satisfy a fixed-size alternative | ||
| testParseIntoErrors< Variant< std::array<int, 3> > >( | ||
| error::exhausted_variants, {1} ); |
There was a problem hiding this comment.
{1} does not create a value that stores an array, it creates a value that stores the number 1. Replace with array{1} or {1, 2}.
There was a problem hiding this comment.
Good catch. {1} went through the single-element value special case and serialised as 1, so that assertion was only covering the not_array path. Changed it to {1, 2}, matching the size_mismatch samples above. Checked that it now exercises the bug: with the old !inner_active_ test, [1,2] into variant<std::array<int, 3>> parses successfully; with the fix it fails with exhausted_variants. Full parse_into suite: 10094 assertions, 0 failures.
|
|



Repro: parse_into a
std::vector<variant2::variant<std::vector<int>, int>>from[[1],2]; it fails witherror::not_array, while the alternatives-swappedvariant<int, std::vector<int>>accepts the same document. Avariant<std::array<int,3>>parsed from[1]reports success and leaves two elements unwritten; nesting such a variant in a map trips theBOOST_ASSERT(false)path inhandler_error_base::on_object_endon debug builds.Cause: the variant handler's
on_array_endtests itsintsentinel with!inner_active_, which is only true for index 0, so while the first alternative is mid-array its closing bracket is routed tosignal_endand terminates the variant instead of reaching the active alternative. The completeness check of the aborted alternative never runs.Fix: compare
inner_active_ < 0, matching the sentinel checks elsewhere in the file. The added tests fail before the change and pass after.🤖 Generated with Claude Code
https://claude.ai/code/session_01C7uBZYRF8M5U3w49QLn4nW