Skip to content

Fix Myers diff backtracking off-by-one (#112)#121

Merged
josephburnett merged 1 commit intojosephburnett:masterfrom
vnykmshr:fix/myers-backtrack-off-by-one
Feb 21, 2026
Merged

Fix Myers diff backtracking off-by-one (#112)#121
josephburnett merged 1 commit intojosephburnett:masterfrom
vnykmshr:fix/myers-backtrack-off-by-one

Conversation

@vnykmshr
Copy link
Copy Markdown
Contributor

@vnykmshr vnykmshr commented Feb 16, 2026

Fixes #112.

buildMyersEdits uses trace[D-1] for backtracking, but the trace is saved before each forward iteration updates V. So trace[D] holds the V state after D-1 steps, not trace[D-1]. Wrong lookup produces garbled edit sequences for arrays with more than 10 elements.

Fix: trace[D-1] -> trace[D] (v2/list.go:1033).

Includes a regression test reproducing the exact scenario from #112.

buildMyersEdits used trace[D-1] for backtracking, but the trace is
saved before each forward iteration updates V. trace[D] holds the V
state after D-1 steps, not trace[D-1]. Wrong lookup produced garbled
edit sequences for arrays with more than 10 elements.

Includes regression test reproducing the exact scenario from #112.
@vnykmshr vnykmshr force-pushed the fix/myers-backtrack-off-by-one branch from 91ec693 to 38cb130 Compare February 16, 2026 17:37
Copy link
Copy Markdown
Owner

@josephburnett josephburnett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The trace indexing fix is correct - trace[D] holds the V state after D-1 steps since it's saved before iteration D runs. Thanks for the fix and the regression test. We'll add broader correctness test coverage for the Myers path as a follow-up.

@josephburnett josephburnett merged commit 26c5ae7 into josephburnett:master Feb 21, 2026
1 check passed
@vnykmshr vnykmshr deleted the fix/myers-backtrack-off-by-one branch February 25, 2026 16:01
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.

Patch breaks the array has more than 10 elements since 2.4.0

2 participants