Fix out-of-order AoT element extensions - #578
Open
davidpavlovschi wants to merge 1 commit into
Open
Conversation
davidpavlovschi
force-pushed
the
fix/aot-out-of-order-unwrap
branch
from
July 28, 2026 19:43
54ddd95 to
2f7a2a5
Compare
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.
Summary
Fixes #577.
An array-of-tables element can be extended by a later nested table header:
This document is valid and
parse()already preserves it byte-for-byte. Because the unrelated table splitsyinto out-of-order parts, accessingdoc["y"]or callingdoc.unwrap()currently tries to append the later implicitatable beside the earlieraAoT and raisesKeyAlreadyPresent.OutOfOrderTableProxy._merge_aot_fragment()now handles this AoT + super-table combination by presenting the last AoT element through a nested proxy spanning both live source tables. It does not merge either source in place, so the original headers keep rendering in their original locations. Reads andunwrap()see the combined element, while edits route back to the correct source part.Starting a subsequent
[[y.a]]element after that nested extension is also valid, but currently fails during parsing because the new fragment is merged only against the last out-of-order part. Once a key is already out of order, the parser now preserves each later super-table as another part and lets the complete proxy/validation path merge it against all prior parts.The regression test verifies:
tomllibinterpretation;Validation:
1052 passedtomllib, round-tripped exactly, and survived live mutationgit diff --checkpassesAgent Drafting Metadata
tomllib, traced the failure to the out-of-order proxy merge, implemented the live-view fix, and ran the complete test suite and formatting checks before opening this PR.