Skip to content

fix array end handling for first variant alternative in parse_into - #1195

Open
Ramya-9353 wants to merge 3 commits into
boostorg:developfrom
Ramya-9353:variant-array-end
Open

Ramya-9353 wants to merge 3 commits into
boostorg:developfrom
Ramya-9353:variant-array-end

Conversation

@Ramya-9353

Copy link
Copy Markdown
Contributor

Repro: parse_into a std::vector<variant2::variant<std::vector<int>, int>> from [[1],2]; it fails with error::not_array, while the alternatives-swapped variant<int, std::vector<int>> accepts the same document. A variant<std::array<int,3>> parsed from [1] reports success and leaves two elements unwritten; nesting such a variant in a map trips the BOOST_ASSERT(false) path in handler_error_base::on_object_end on debug builds.
Cause: the variant handler's on_array_end tests its int sentinel with !inner_active_, which is only true for index 0, so while the first alternative is mid-array its closing bracket is routed to signal_end and 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

@cppalliance-bot

cppalliance-bot commented Sep 4, 2026 •

Copy link
Copy Markdown

GCOVR code coverage report https://1195.json.prtest2.cppalliance.org/gcovr/index.html
LCOV code coverage report https://1195.json.prtest2.cppalliance.org/genhtml/index.html
Coverage Diff Report https://1195.json.prtest2.cppalliance.org/diff-report/index.html

Build time: 2026-09-25 17:55:29 UTC

@codecov

codecov Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.47%. Comparing base (82398f9) to head (1a0e3d2).
⚠️ Report is 8 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             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     
Files with missing lines Coverage Δ
include/boost/json/detail/parse_into.hpp 99.33% <100.00%> (-0.01%) ⬇️

... and 9 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 82398f9...1a0e3d2. Read the comment docs.

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

@cppalliance-bot

Copy link
Copy Markdown

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.
@Ramya-9353

Copy link
Copy Markdown
Contributor Author

Pushed a fix for the codecov/project failure. The two lines it lost are into_handler::signal_end, which on develop was only reached through the misrouted ] (14 hits in the parse_into suite before the change, 0 after). The top handler is never inside an array, so nothing can forward an array end to it now; I've excluded it with LCOV_EXCL markers, same as handler_error_base.

@cppalliance-bot

cppalliance-bot commented Sep 18, 2026 •

Copy link
Copy Markdown

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

@cppalliance-bot

Copy link
Copy Markdown

Comment thread test/parse_into.cpp Outdated

// an incomplete array must not satisfy a fixed-size alternative
testParseIntoErrors< Variant< std::array<int, 3> > >(
error::exhausted_variants, {1} );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{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}.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cppalliance-bot

Copy link
Copy Markdown

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