fix: preserve location data through clone operations - #423
Draft
toddr-bot wants to merge 2 commits into
Draft
Conversation
line_number and column_number return undef on cloned elements because location data is not preserved through the clone operation. Tests are marked TODO until the fix is applied. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Element::clone now indexes locations before deep-copying so that _location cache survives into the clone. This fixes line_number and column_number returning undef on cloned elements (issue #80). Document::normalized flushes locations on the clone before normalizing, since location cache is positional data that should not affect semantic comparison. Fixes #80 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
line_numberandcolumn_numberreturnundefon cloned elements because the_locationcache is lazily computed viaDocument->index_locations, which requires a Document parent that clones don't have.The fix:
Element::clonenow indexes locations before the deep copy so that_locationdata survives into the clone.Document::normalizedflushes locations on its clone before normalizing, since location cache is positional data that should not affect semantic comparison.Fixes #80
Changes
Element::clonecallsDocument->index_locationsbeforeClone::cloneso location cache is deep-copiedDocument::normalizedflushes locations on the clone before passing toPPI::Normal->processppi_element_flush.tpartial-index subtest to flush stale clone locations before reindexingppi_element_clone_location.twith tests for clone + location on statements and tokensTest plan
t/ppi_element_clone_location.tverifiesline_number/column_numberwork on cloned statements and tokensGenerated by Kōan /fix
Quality Report
Changes: 4 files changed, 57 insertions(+), 8 deletions(-)
Code scan: clean
Tests: skipped
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline