Skip to content

Fix two bugs in tab-completion common-prefix matching - #3

Merged
vbfox merged 3 commits into
masterfrom
claude/port-pr2-bugfixes
Jul 26, 2026
Merged

Fix two bugs in tab-completion common-prefix matching#3
vbfox merged 3 commits into
masterfrom
claude/port-pr2-bugfixes

Conversation

@vbfox

@vbfox vbfox commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Summary

While reviewing PR #2 (which ports the upstream completion popup feature), that PR's description called out two pre-existing bugs in the existing F# port's tab-completion common-prefix matching (cmdTabOrComplete in FsGetLine.fs), unrelated to the popup feature itself. This PR extracts and fixes just those two bugs against master, with regression tests, so they land independently of the larger popup port.

  • A missing loop increment that could hang indefinitely whenever two or more completions shared so much as their first character.
  • A missing short-circuit (< instead of <=, and two independent ifs instead of elif) that could index a shorter completion string out of bounds once the scan reached exactly its length.

Note on the second bug

PR #2's own fix for this only added the elif short-circuit but kept the < comparison. I verified empirically that this is still incomplete: it crashes when the longer completion is listed first (e.g. ["abc"; "ab"]), because PR #2's regression test happened to list the shorter completion first, which never exercises the crash path. The same < p (not <=) exists in upstream mono's C# getline.cs too, so this is a latent bug there as well, not something introduced by the F# port. This PR fixes it correctly with <=.

Commits

  1. Add test infrastructure (Expecto) — adds the BlackFox.FsGetLine.Tests project, wired into the solution and the FAKE build (RunTests task, CI/Default depend on it). Same setup as PR Port completion popup window from upstream getline.cs #2, without the popup feature or its tests.
  2. Fix infinite loop in tab-completion common-prefix matching — extracts the logic into a testable commonPrefixLength function and adds the missing i <- i + 1.
  3. Fix out-of-bounds index in tab-completion common-prefix matching — changes the length check to <= and short-circuits it with elif.

Test plan

  • dotnet build FsGetLine.sln -c Release succeeds
  • dotnet test passes (2/2)
  • Confirmed each bug reproduces (hang / IndexOutOfRangeException) by running the pre-fix logic in a timeout-guarded script before applying each fix

Generated by Claude Code

vbfox and others added 3 commits July 25, 2026 15:43
Adds a BlackFox.FsGetLine.Tests project, matching FoxSharp's convention,
wired into the solution and the FAKE build as a RunTests task that CI
now depends on (previously a DoNothing placeholder). No tests yet;
regression tests for specific bugs land in follow-up commits.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
cmdTabOrComplete's inner scan over the other candidates never advanced
its index (`i`), so once two or more completions shared a character at
some position, the loop condition (`i < ncompletions && not mismatch`)
kept re-checking the same index forever instead of eventually setting
`mismatch` or exhausting the candidates. Any tab-completion with two or
more matches sharing so much as their first character would hang.

Extracted the logic into a top-level `commonPrefixLength` function so
it can be unit tested, and added the missing `i <- i + 1`. Confirmed
the pre-fix code hangs on the regression input by running it in a
timeout-guarded task.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@vbfox
vbfox force-pushed the claude/port-pr2-bugfixes branch from dc0b1ae to 6f7cbd3 Compare July 26, 2026 21:44
@vbfox

vbfox commented Jul 26, 2026

Copy link
Copy Markdown
Owner Author

Rewrote part of the logic over LLM output to be more FSharpy and have some FsCheck tests

@vbfox
vbfox merged commit 87ea3f5 into master Jul 26, 2026
3 checks passed
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