Skip to content

fix: preserve location data through clone operations - #423

Draft
toddr-bot wants to merge 2 commits into
masterfrom
koan.toddr.bot/fix-issue-80
Draft

fix: preserve location data through clone operations#423
toddr-bot wants to merge 2 commits into
masterfrom
koan.toddr.bot/fix-issue-80

Conversation

@toddr-bot

@toddr-bot toddr-bot commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

line_number and column_number return undef on cloned elements because the _location cache is lazily computed via Document->index_locations, which requires a Document parent that clones don't have.

The fix: Element::clone now indexes locations before the deep copy so that _location data survives into the clone. Document::normalized flushes locations on its clone before normalizing, since location cache is positional data that should not affect semantic comparison.

Fixes #80

Changes

  • Element::clone calls Document->index_locations before Clone::clone so location cache is deep-copied
  • Document::normalized flushes locations on the clone before passing to PPI::Normal->process
  • Updated ppi_element_flush.t partial-index subtest to flush stale clone locations before reindexing
  • Added ppi_element_clone_location.t with tests for clone + location on statements and tokens

Test plan

  • New test t/ppi_element_clone_location.t verifies line_number/column_number work on cloned statements and tokens
  • Full test suite passes (70 files, 53102 tests)

Generated 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

toddr-bot and others added 2 commits April 27, 2026 06:16
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>
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.

Line numbers not working after clone

1 participant