Skip to content

Fix mistaken slice delete in extractFromSymbol - #65480

Merged
Jake Bailey (jakebailey) merged 1 commit into
microsoft:mainfrom
jakebailey:compiler-fixes/autoimport-export-star
Nov 13, 2026
Merged

Jake Bailey (jakebailey) merged 1 commit into
microsoft:mainfrom
jakebailey:compiler-fixes/autoimport-export-star

Conversation

@jakebailey

Copy link
Copy Markdown
Member

I haven't found a test case, but this would crash if the second condition were true because the index is out of bounds.

An ignored symbol does not establish that it exists in the resolved
export slice. Only remove named entries when their index is valid;
createExport already excludes prototype symbols from remaining exports.
Copilot AI balanced review requested due to automatic review settings November 13, 2026 05:19
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 13, 2026
@typescript-automation typescript-automation Bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Nov 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The behavior-changing case where idx == -1 and shouldIgnoreSymbol(namedExport) is true lacks a regression test verifying that extraction completes and retains the expected exports.

1 open issue
What changed in this PR

This PR fixes a potential out-of-bounds panic in the language server’s auto-import symbol extraction.

Changes:

  • Deletes a named export from the slice only when its index is valid.
  • Removes shouldIgnoreSymbol from the deletion guard so it cannot trigger deletion at index -1.
File Description
tsc/​internal/​ls/​autoimport/​extract.go Guards slice deletion with a successful index lookup.

Review effort: Balanced

Comment thread tsc/internal/ls/autoimport/extract.go Resolved
if name != ast.InternalSymbolNameExportStar {
idx := slices.Index(allExports, namedExport)
if idx >= 0 || shouldIgnoreSymbol(namedExport) {
if idx >= 0 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It feels like the bug here is this was meant to be an && or something similar.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As far as I can tell, no, shouldIgnoreSymbol always returns false here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So, I guess this is actually a noop, but it looks like a bug due to the !!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I think the PR is correct. I think this must have been the result of refactoring how the slice is built/modified. The logic is sound if you think of the condition as "should exclude this symbol" rather than "should delete this symbol." It seems like I should be able to come up with a test though. Let me try for a minute.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Never mind, I also can't come up with a test that exercises this

@github-project-automation github-project-automation Bot moved this from Not started to Needs merge in PR Backlog Nov 13, 2026
@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queue Nov 13, 2026
Merged via the queue into microsoft:main with commit 2246758 Nov 13, 2026
34 checks passed
@jakebailey
Jake Bailey (jakebailey) deleted the compiler-fixes/autoimport-export-star branch November 13, 2026 19:05
@github-project-automation github-project-automation Bot moved this from Needs merge to Done in PR Backlog Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants