Repository navigation
Fix mistaken slice delete in extractFromSymbol - #65480
Jake Bailey (jakebailey) merged 1 commit into
Conversation
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.
There was a problem hiding this comment.
🟡 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
shouldIgnoreSymbolfrom 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
| if name != ast.InternalSymbolNameExportStar { | ||
| idx := slices.Index(allExports, namedExport) | ||
| if idx >= 0 || shouldIgnoreSymbol(namedExport) { | ||
| if idx >= 0 { |
There was a problem hiding this comment.
It feels like the bug here is this was meant to be an && or something similar.
There was a problem hiding this comment.
As far as I can tell, no, shouldIgnoreSymbol always returns false here
There was a problem hiding this comment.
So, I guess this is actually a noop, but it looks like a bug due to the !!
There was a problem hiding this comment.
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.
Andrew Branch (andrewbranch)
left a comment
There was a problem hiding this comment.
Never mind, I also can't come up with a test that exercises this

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