Skip to content

fix(postprocess): demote hollow composite moves after eviction - #243

Merged
HarshK97 merged 1 commit into
mainfrom
fix/demote-cascade-evicted-moves
Oct 10, 2026
Merged

HarshK97 merged 1 commit into
mainfrom
fix/demote-cascade-evicted-moves

Conversation

@HarshK97

Copy link
Copy Markdown
Owner

Problem

  1. When we demote an outer container move (like an if statement) down to a Delete and Insert, all its inner tokens get evicted. But if an inner composite expression (like a condition binary_expression) had its own Move action, it slipped past our hollow container checks because those only ran on blocks or delimited containers like {} or ().
  2. So even when every single payload leaf inside the expression got wiped out by the demotion cascade, the outer expression move survived. That left a hollow move shell that painted the destination code in move color while deleting the whole thing on the source side.

What Changed

  • In shouldDemoteMove, check if a composite node had mapped payload leaves that all got evicted by an ancestor demotion cascade, and demote it to Delete and Insert too.
  • Checked unevicted leaves first so we can short-circuit on the very first surviving leaf in the normal case, instead of walking the AST descendants twice for every candidate move.
  • Added a regression test in internal/postprocess/normalize_test.go to make sure condition expressions inside demoted control flow don't hang around as hollow moves.

When an outer container move (like an if statement) is demoted to
delete+insert, its inner tokens get evicted. Inner composite nodes with
their own explicit move (such as a condition's binary_expression) were
surviving even after every payload leaf was wiped out, leaving an empty
move shell that highlighted destination tokens in move color while
deleting the source side.

Demote composite moves to delete+insert when all of their mapped leaves
were evicted by an ancestor demotion cascade.

- postprocess: demote composite moves whose mapped leaves were all
evicted
- postprocess: evaluate unevicted leaves first to short-circuit the hot
path
- tests: verify hollow binary_expression moves are demoted after
eviction
@HarshK97
HarshK97 merged commit b0b1d9f into main Oct 10, 2026
17 checks passed
@HarshK97
HarshK97 deleted the fix/demote-cascade-evicted-moves branch October 10, 2026 04:33
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.

1 participant