Skip to content

fix(repl): fix panic when pressing Tab at beginning of line#32750

Merged
bartlomieju merged 3 commits intomainfrom
fix/repl-tab-completion-panic
Mar 17, 2026
Merged

fix(repl): fix panic when pressing Tab at beginning of line#32750
bartlomieju merged 3 commits intomainfrom
fix/repl-tab-completion-panic

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

Summary

  • Fixes a panic (usize underflow) in the REPL when pressing Tab at the beginning of a line that contains text
  • The get_expr_from_line_at_pos function was looking at text after the cursor to determine the completion expression, then subtracting its length from cursor position 0, causing an underflow to usize::MAX
  • Fix: only consider text before the cursor when determining the expression to complete

Reproduction steps

  1. Run deno to enter REPL
  2. Type Date(
  3. Move cursor to beginning of the line (Home key or Ctrl+A)
  4. Press Tab

Test plan

  • Manually verified the panic no longer occurs with the above reproduction steps
  • Verified normal tab completion still works (e.g. typing Dat + Tab completes to Date)

Closes #28038

🤖 Generated with Claude Code

bartlomieju and others added 3 commits March 15, 2026 15:32
When the cursor was at the beginning of a line containing text (e.g.
typing `Date(` then pressing Home and Tab), the REPL's fallback tab
completion would panic due to a usize underflow. The
`get_expr_from_line_at_pos` function was looking at text *after* the
cursor to determine the expression, then subtracting its length from
the cursor position (0), causing an underflow.

Fix: only consider text before the cursor position when determining
the expression to complete, which is the correct behavior for tab
completion.

Closes #28038

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

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

LGTM

@bartlomieju bartlomieju merged commit 457de64 into main Mar 17, 2026
112 checks passed
@bartlomieju bartlomieju deleted the fix/repl-tab-completion-panic branch March 17, 2026 14:46
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.

Deno panic in Terminal

2 participants