Skip to content

Fix nil pointer dereference in explainRedirectAndImpliedFormat#3380

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-nil-pointer-dereference-another-one
Draft

Fix nil pointer dereference in explainRedirectAndImpliedFormat#3380
Copilot wants to merge 3 commits intomainfrom
copilot/fix-nil-pointer-dereference-another-one

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 9, 2026

explainRedirectAndImpliedFormat panics when GetSourceFileByPath returns nil for a given path. The nil *ast.SourceFile is assigned to the ast.HasFileName interface, then .Path() is called on it.

  • Add nil guard after GetSourceFileByPath, returning nil (empty diagnostics) early when the source file isn't found
  • Add test case that reproduces the crash: on a case-sensitive filesystem, two root files with different casing (/src/MyFile.ts and /src/myFile.ts) where only one exists, triggering a file casing diagnostic whose file path references the missing file

…ource file not found

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/dbf27f2f-19ac-4356-bb00-70aa15ecfceb

Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix nil pointer dereference during diagnostics request Fix nil pointer dereference in explainRedirectAndImpliedFormat Apr 9, 2026
Copilot AI requested a review from DanielRosenwasser April 9, 2026 19:13
@DanielRosenwasser
Copy link
Copy Markdown
Member

@copilot try to figure out a test case for this.

…dFormat

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/07018514-60b1-489a-9f1f-f4794a3d06ec

Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 9, 2026

@copilot try to figure out a test case for this.

Added a test in 4e3a3adf. The scenario: on a case-sensitive filesystem, two root files with different casing (/src/MyFile.ts and /src/myFile.ts) where only the lowercase version exists. This triggers a file casing diagnostic in the include processor whose file path points to the missing /src/MyFile.ts. When explainRedirectAndImpliedFormat is called during diagnostics computation, GetSourceFileByPath returns nil for that path, causing the nil pointer dereference. Verified the test fails without the fix and passes with it.

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.

nil pointer dereference during diagnostics request

2 participants