Skip to content

fix(engine,postprocess): align binary chains and drifted expressions - #248

Merged
HarshK97 merged 1 commit into
mainfrom
fix/binary-chain-and-stationary-expr-moves
Oct 11, 2026
Merged

HarshK97 merged 1 commit into
mainfrom
fix/binary-chain-and-stationary-expr-moves

Conversation

@HarshK97

Copy link
Copy Markdown
Owner

Problem

  1. When deleting an operand from a binary chain like (A || B) || C down to B || C, BottomUp let the inner (A || B) grab B || C across the operator. The parent node was the one that actually matched, but the inner node grabbed it first and threw off the rest of the chain.
  2. In postprocess, stationary expression checks looked at raw line numbers (StartRow). If lines were added earlier in the file, untouched statements shifted down. Expressions inside them failed the line check and showed up as false moves.

What Changed

  • internal/engine/bottom-up.go: Added hasCrossSideOperatorMismatch so inner binary expressions don't steal matches across an operator when their unmapped parent already matches that side.
  • internal/postprocess/normalize.go: Added isStatementStationary to check if a statement actually stayed put structurally, ignoring line shifts from edits earlier in the file.
  • internal/postprocess/normalize.go: Made isStationaryExpressionMove and requiredMoveThreshold measure drift relative to the enclosing statement instead of the whole file.
  • Added regression tests for binary chain operand deletion and drifted stationary expressions, and refreshed golden fixtures.

Deleting an operand from a binary chain like (A || B) || C let inner
binary expressions grab B || C across the operator, shifting the chain
mapping off by one level. Meanwhile, edits earlier in the file drifted
statement row numbers, causing stationary expressions inside untouched
statements to fail absolute line checks and emit false moves.

- engine: reject inner binary expression matches when shared operands
  cross operator sides and an unmapped parent binary expression keeps
  them on the same side, preventing off-by-one chain misalignment
- postprocess: use structural stationarity and statement-relative row
  offsets so line drift from earlier edits doesn't trigger false moves
- tests: add coverage for binary chain truncation and drifted stationary
  expressions, and refresh integration golden fixtures
@HarshK97
HarshK97 merged commit bce794d into main Oct 11, 2026
17 checks passed
@HarshK97
HarshK97 deleted the fix/binary-chain-and-stationary-expr-moves branch October 11, 2026 05: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